Docker : Use Dockerfile#12015/11/12 |
Use Dockerfile and create Docker images automatically.
It is also useful for configuration management. |
|||||||||||||||||||||||||||||
[1] | The format of Dockerfile is [INSTRUCTION arguments] . Refer to the following description for INSTRUCTION.
|
[2] | For example, Create a Dockerfile to install httpd and add index.html. |
[root@dlp ~]#
vi Dockerfile # create new FROM fedora MAINTAINER serverworld <admin@srv.world> RUN dnf -y install httpd RUN echo "Hello DockerFile" > /var/www/html/index.html CMD /usr/bin/whereis httpd # build image ⇒ docker build -t [image name]:[tag] [root@dlp ~]# docker build -t serverworld/httpd:v1.0 . Sending build context to Docker daemon 11.78 kB Step 0 : FROM fedora ---> c7d2f0130dae Step 1 : MAINTAINER serverworld <admin@srv.world> ---> Running in 221f62606bce ---> d430c0909468 ..... ..... Removing intermediate container 3cb67d3a9aa5 Successfully built b6f3fceaba56[root@dlp ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE serverworld/httpd v1.0 b6f3fceaba56 35 seconds ago 331.6 MB docker.io/fedora latest c7d2f0130dae 9 days ago 204.3 MB # execute without arguments, then the command specified by CMD is executed [root@dlp ~]# docker run serverworld/httpd:v1.0 httpd: /usr/sbin/httpd /usr/lib64/httpd /etc/httpd /usr/share/httpd /usr/share/man/man8/httpd.8.gz # execute with arguments, then the command specified by CMD is overwritten and the arguments is executed [root@dlp ~]# docker run serverworld/httpd:v1.0 /usr/bin/cat /var/www/html/index.html Hello DockerFile |
Sponsored Link |