Steps to Build and Run a project in Docker

The objective of this article to explain how to clone a project from Github, how to build and run a project using docker. To execute the following commands in this article we are using Windows Power Shell app. Copy the below link to clone doodle project as sown in the below snapshot.

 git clone https://github.com/docker/doodle.git

Open the Power shell app in windows, paste the above link and enter to clone the doodle project into your local from Github. Look at the below screenshot, click on Next Step button to proceed further.

Use the below command to build the doodle project which you cloned. Look at the below snapshot to get the command.

cd doodle\cheers2019 ; docker build -t subbareddyroyal/cheers2019 .

If you have selected the checkbox to use Windows containers instead of Linux containers, you may end up with these build problems with windows containers in Docker.

Look at the complete build log in below,

PS C:\Users\USER\doodle\cheers2019> docker build -t subbareddyroyal/cheers2019 .
Sending build context to Docker daemon  13.31kB
Step 1/9 : FROM golang:1.11-alpine AS builder
1.11-alpine: Pulling from library/golang
9d48c3bd43c5: Pull complete
7f94eaf8af20: Pull complete
9fe9984849c1: Pull complete
ec448270508e: Pull complete
65ba82af53f7: Pull complete
Digest: sha256:09e47edb668c2cac8c0bbce113f2f72c97b1555d70546dff569c8b9b27fcebd3
Status: Downloaded newer image for golang:1.11-alpine
 ---> e116d2efa2ab
Step 2/9 : RUN apk add --no-cache git
 ---> Running in 12294dfcd16f
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
(1/5) Installing nghttp2-libs (1.39.2-r0)
(2/5) Installing libcurl (7.66.0-r0)
(3/5) Installing expat (2.2.8-r0)
(4/5) Installing pcre2 (10.33-r0)
(5/5) Installing git (2.22.0-r0)
Executing busybox-1.30.1-r2.trigger
OK: 21 MiB in 20 packages
Removing intermediate container 12294dfcd16f
 ---> ad60dc062125
Step 3/9 : RUN go get github.com/pdevine/go-asciisprite
 ---> Running in 1aac9775b8fc
Removing intermediate container 1aac9775b8fc
 ---> 36bc85ba1d54
Step 4/9 : WORKDIR /project
 ---> Running in b6b7fb080c76
Removing intermediate container b6b7fb080c76
 ---> 869c1330f798
Step 5/9 : COPY cheers.go .
 ---> 14ad50d63b75
Step 6/9 : RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' 
-o cheers cheers.go
 ---> Running in f7ec6a7e31a5
Removing intermediate container f7ec6a7e31a5
 ---> 1860a3c041b4
Step 7/9 : FROM scratch
 --->
Step 8/9 : COPY --from=builder /project/cheers /cheers
 ---> 57ba1a37badc
Step 9/9 : ENTRYPOINT ["/cheers"]
 ---> Running in 4121ff99ce65
Removing intermediate container 4121ff99ce65
 ---> e51c83d4c18f
Successfully built e51c83d4c18f
Successfully tagged subbareddyroyal/cheers2019:latest
SECURITY WARNING: You are building a Docker image from Windows against
a non-Windows Docker host.
All files and directories added to build context will have '-rwxr-xr-x' permissions.
It is recommended to double check and reset permissions for sensitive files
and directories.

Now project build is successfully completed. Then you go to the next step to get the command to run. Look at the below snapshot.

docker run -it –rm subbareddyroyal/cheers2019

When you run the above command, you can see the screen like below and moving the docker symbol.

Now issue the below command to ship this into docker.

docker login ; docker push subbareddyroyal/cheers2019

Look at the below image to see the Pushing progress into Docker. Docker will expect you to provide the authentication details to complete the login process. Once you authenticated successfully, Docker starts the actual Push process.

I hope this is helped you to understand the basics of the Docker. Thanks for visiting my website.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s