Sign inSign up

archananagaraj/demo_builddockerimageusingdockerfile

By archananagaraj

•Updated over 7 years ago

Demo to show how to build docker image by writing dockerfile

Image
0

106

archananagaraj/demo_builddockerimageusingdockerfile repository overview

Step1:

docker run -it centos:latest. --> Run any image of your choice from the docker hub ( Here I have used cents:latest as an example)

git --> confirm git is not installed ( We are going to install git via docker file later in step 2)

docker images. --> Confirm the image is running.

docker ps -a -->Note the container id

docker commit b08dc45b19b5 archananagaraj/demo_builddockerimageusingdockerfile:CentosWithNogit. -->Commit the changes( in this case no changes made to the image yet) OR you may use docker tag command to tag your image

docker push archananagaraj/demo_builddockerimageusingdockerfile:CentosWithNogit. --> Push the image to docker repo


Step2:

Creating docker file Note: Docker file is a text document with no extension with the name starting with capitalD that contains all the instructions user provide to assemble an image Each instruction will create a new image layer to the image. Instructions provide what to do when building the image

Archanas-MacBook-Air:~ archananagaraja$ touch Dockerfile

vi Dockerfile --> Here is where you write the instructions to perform.

FROM centos:latest. --> install/pull the latest centos from docker hub

RUN yum install git --> install git

docker build -t archananagaraj/demo_builddockerimageusingdockerfile . --> build the image using docker file which is in the current directory -: make sure your current working dir has the docker file placed.

docker images --> note the image id

docker run -it . --> note the container id

docker commit e3b2f04c99e3 archananagaraj/demo_builddockerimageusingdockerfile:centoswithgit. --> give a tagename here OR you may use docker tag command to tag your image

docker push archananagaraj/demo_builddockerimageusingdockerfile:centoswithgit. --> push to docker repo


Note: Note the sizes of the images before and after the changes done

Archanas-MacBook-Air:Desktop archananagaraja$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE archananagaraj/demo_builddockerimageusingdockerfile latest 94ebc929cb24 About a minute ago 360MB archananagaraj/demo_builddockerimageusingdockerfile CentosWithNogit b48b6c835afb 29 minutes ago 202MB

Tag summary

Content type

Image

Digest

Size

125.1 MB

Last updated

over 7 years ago

docker pull archananagaraj/demo_builddockerimageusingdockerfile:centoswithgit