How to create custom image from custom docker file
[root@ip-172-31-85-137 ~]# mkdir dockerfiles
[root@ip-172-31-85-137 ~]# cd dockerfiles/
[root@ip-172-31-85-137 dockerfiles]# vi Dockerfile
[root@ip-172-31-85-137 dockerfiles]# cat Dockerfile
FROM ubuntu:16.04
[root@ip-172-31-85-137 dockerfiles]# docker image build -t rajubuntu:1 .
Sending build context to Docker daemon 2.048kB
Step 1/1 : FROM ubuntu:16.04
16.04: Pulling from library/ubuntu
35b42117c431: Pull complete
ad9c569a8d98: Pull complete
293b44f45162: Pull complete
0c175077525d: Pull complete
Digest: sha256:a4d8e674ee993e5ec88823391de828a5e9286a1597b731eaecaaf9066cfdf539
Status: Downloaded newer image for ubuntu:16.04
---> 13c9f1285025
Successfully built 13c9f1285025
Successfully tagged rajubuntu:1
[root@ip-172-31-85-137 dockerfiles]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
rajubuntu 1 13c9f1285025 3 weeks ago 119MB
ubuntu 16.04 13c9f1285025 3 weeks ago 119MB
[root@ip-172-31-85-137 dockerfiles]# docker container run -it rajubuntu:1
root@77099511689e:/# tree ----not found
bash: tree: command not found
root@77099511689e:/# exit
exit
-----------------------------------------------------------------------------
[root@ip-172-31-85-137 dockerfiles]# vi Dockerfile
[root@ip-172-31-85-137 dockerfiles]# cat Dockerfile
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y tree
[root@ip-172-31-85-137 dockerfiles]# docker image build -t rajubuntu:2 .
[root@ip-172-31-85-137 dockerfiles]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
rajubuntu 2 13c9f1285025 3 weeks ago 119MB
rajubuntu 1 13c9f1285025 3 weeks ago 119MB
ubuntu 16.04 13c9f1285025 3 weeks ago 119MB
[root@ip-172-31-85-137 dockerfiles]# docker container run -it rajubuntu:2
root@1fd15222b539:/#tree ------already install
--------------------------------------------------------------------------------------------------
[root@ip-172-31-85-137 dockerfiles]# vi Dockerfile
[root@ip-172-31-85-137 dockerfiles]# cat Dockerfile
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y tree
RUN touch /tmp/1.txt
RUN touch /tmp/2.txt
RUN touch /tmp/3.txt
RUN touch /tmp/4.txt
RUN touch /tmp/5.txt
RUN touch /tmp/6.txt
[root@ip-172-31-85-137 ~]# mkdir dockerfiles
[root@ip-172-31-85-137 ~]# cd dockerfiles/
[root@ip-172-31-85-137 dockerfiles]# vi Dockerfile
[root@ip-172-31-85-137 dockerfiles]# cat Dockerfile
FROM ubuntu:16.04
[root@ip-172-31-85-137 dockerfiles]# docker image build -t rajubuntu:1 .
Sending build context to Docker daemon 2.048kB
Step 1/1 : FROM ubuntu:16.04
16.04: Pulling from library/ubuntu
35b42117c431: Pull complete
ad9c569a8d98: Pull complete
293b44f45162: Pull complete
0c175077525d: Pull complete
Digest: sha256:a4d8e674ee993e5ec88823391de828a5e9286a1597b731eaecaaf9066cfdf539
Status: Downloaded newer image for ubuntu:16.04
---> 13c9f1285025
Successfully built 13c9f1285025
Successfully tagged rajubuntu:1
[root@ip-172-31-85-137 dockerfiles]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
rajubuntu 1 13c9f1285025 3 weeks ago 119MB
ubuntu 16.04 13c9f1285025 3 weeks ago 119MB
[root@ip-172-31-85-137 dockerfiles]# docker container run -it rajubuntu:1
root@77099511689e:/# tree ----not found
bash: tree: command not found
root@77099511689e:/# exit
exit
-----------------------------------------------------------------------------
[root@ip-172-31-85-137 dockerfiles]# vi Dockerfile
[root@ip-172-31-85-137 dockerfiles]# cat Dockerfile
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y tree
[root@ip-172-31-85-137 dockerfiles]# docker image build -t rajubuntu:2 .
[root@ip-172-31-85-137 dockerfiles]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
rajubuntu 2 13c9f1285025 3 weeks ago 119MB
rajubuntu 1 13c9f1285025 3 weeks ago 119MB
ubuntu 16.04 13c9f1285025 3 weeks ago 119MB
[root@ip-172-31-85-137 dockerfiles]# docker container run -it rajubuntu:2
root@1fd15222b539:/#tree ------already install
--------------------------------------------------------------------------------------------------
[root@ip-172-31-85-137 dockerfiles]# vi Dockerfile
[root@ip-172-31-85-137 dockerfiles]# cat Dockerfile
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y tree
RUN touch /tmp/1.txt
RUN touch /tmp/2.txt
RUN touch /tmp/3.txt
RUN touch /tmp/4.txt
RUN touch /tmp/5.txt
RUN touch /tmp/6.txt
[root@ip-172-31-85-137 dockerfiles]# docker image build -t rajubuntu:3 .
[root@ip-172-31-85-137 dockerfiles]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
rajubuntu 3 31a9e63bc1ee 3 minutes ago 146MB
rajubuntu 2 09a779b278b9 21 minutes ago 146MB
rajubuntu 1 13c9f1285025 3 weeks ago 119MB
ubuntu 16.04 13c9f1285025 3 weeks ago 119MB
[root@ip-172-31-85-137 dockerfiles]# docker container run -it rajubuntu:3
root@a4d906421e5a:/# cd tmp/
root@a4d906421e5a:/tmp# ls
1.txt 2.txt 3.txt 4.txt 5.txt 6.txt
root@a4d906421e5a:/tmp# tree .
.
|-- 1.txt
|-- 2.txt
|-- 3.txt
|-- 4.txt
|-- 5.txt
`-- 6.txt
0 directories, 6 files
root@a4d906421e5a:/tmp#
--------------------------------------------------------------------------------------------------
[root@ip-172-31-85-137 dockerfiles]# vi Dockerfile
[root@ip-172-31-85-137 dockerfiles]# cat Dockerfile
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y tree
RUN touch /tmp/1.txt
RUN touch /tmp/2.txt
RUN touch /tmp/3.txt
RUN touch /tmp/4.txt
RUN touch /tmp/5.txt
RUN touch /tmp/6.txt
RUN echo "Raj Kumar Gupta"
RUN echo "Raj Kumar Gupta"
RUN echo "Raj Kumar Gupta"
RUN echo "Raj Kumar Gupta"
[root@ip-172-31-85-137 dockerfiles]# docker image build -t rajubuntu:4 .
Note:- When ever you want to add any or change any thing in docker file try to do at the end of file because if you do in begging or in middle then all the command after that will run but if add in the end then only that line will be run rest will take from cache and you will save your time
No comments:
Post a Comment