Docker series: 6. Build a Docker image from file

Jay Bilgaye
cloudscoop
Published in
2 min readOct 5, 2019

These notes will help you build docker image from the file.

  1. Create a directory
[root@machine1 ~]# mkdir myImage
[root@machine1 ~]# cd myImage/
[root@machine1 myImage]# vi Dockerfile

2.Create a file with the following content

[root@machine1 myImage]# cat Dockerfile
FROM centos:latest
MAINTAINER “jack sparrow”
RUN yum install -y git wget python perlCMD [“echo” , “This is Dockerfile which will create centos 7 image with above packeges.” ]

3. Use the following command;

docker build -t mycentosimage:pack1.0 .[root@machine1 myImage]# docker build -t mycentosimage:pack1.0 .
Sending build context to Docker daemon 2.048kB
Step 1/4 : FROM centos:latest
---> 9f38484d220f
Step 2/4 : MAINTAINER "jack sparrow"
---> Running in 82b57c8a3e0e
Removing intermediate container 82b57c8a3e0e
---> 9c6df2adc37d
Step 3/4 : RUN yum install -y git wget python perl
---> Running in c2a23dd2d07b
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: mirror.dhakacom.com
* extras: centos-hcm.viettelidc.com.vn
* updates: centos-hcm.viettelidc.com.vn
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:1.8.3.1-20.el7 will be installed
....
....
....
Complete!
Removing intermediate container c2a23dd2d07b
---> 1d5fb1159e18
Step 4/4 : CMD ["echo" , "This is Dockerfile which will create centos 7 image with above packeges." ]
---> Running in 7f7cd5e0834c
Removing intermediate container 7f7cd5e0834c
---> eca72e1a5c53
Successfully built eca72e1a5c53
Successfully tagged mycentosimage:pack1.0

4. Verify image name as mycentosimage:

[root@machine1 myImage]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
mycentosimage pack1.0 eca72e1a5c53 2 minutes ago 385MB
jacksparrow007/hadooppresetup latest 2c3a110c721e 13 hours ago 658MB
ubuntu latest 4c108a37151f 4 weeks ago 64.2MB
centos centos7 9f38484d220f 4 months ago 202MB
centos latest 9f38484d220f 4 months ago 202MB
hello-world latest fce289e99eb9 6 months ago 1.84kB
[root@machine1 myImage]#

5. Run your Docker image:

[root@machine1 myImage]# docker run mycentosimage:pack1.0
This is Dockerfile which will create centos 7 image with above packeges.
[root@machine1 myImage]#

Series next read,

https://medium.com/cloudscoop/cloudscoop-remove-docker-container-c752f2e1a91d

--

--