Docker : Use Dockerfile2021/04/06 |
Use Dockerfile and create Docker images automatically.
It is also useful for configuration management. |
|
[1] | For example, Create a Dockerfile that Apache httpd is installed and started. |
[root@dlp ~]#
vi Dockerfile # create new FROM centos MAINTAINER ServerWorld <admin@srv.world> RUN dnf -y install httpd RUN echo "Dockerfile Test on Aapche httpd" > /var/www/html/index.html EXPOSE 80 CMD ["-D", "FOREGROUND"] ENTRYPOINT ["/usr/sbin/httpd"] # build image ⇒ docker build -t [image name]:[tag] . [root@dlp ~]# docker build -t srv.world/centos-httpd:latest ./ Sending build context to Docker daemon 11.26kB Step 1/7 : FROM centos ---> 300e315adb2f Step 2/7 : MAINTAINER ServerWorld <admin@srv.world> ---> Running in 745ea9e6168a Removing intermediate container 745ea9e6168a ---> bff9628ba408 Step 3/7 : RUN dnf -y install httpd ---> Running in a7985088ba17 ..... ..... Successfully built 83fe1ffbabdb Successfully tagged srv.world/centos-httpd:latest[root@dlp ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE srv.world/centos-httpd latest 83fe1ffbabdb 58 seconds ago 250MB srv.world/centos-nginx latest ae7ab6688f5e 4 minutes ago 289MB centos latest 300e315adb2f 3 months ago 209MB # run container [root@dlp ~]# docker run -d -p 8081:80 srv.world/centos-httpd c1530e2ae462b20b201891a0e7262b7deb890ce02b85ccf733c4e48b4bc8a78d[root@dlp ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c1530e2ae462 srv.world/centos-httpd "/usr/sbin/httpd -D …" 10 seconds ago Up 9 seconds 0.0.0.0:8081->80/tcp thirsty_jones # verify accesses [root@dlp ~]# curl localhost:8081 Dockerfile Test on Aapche httpd |
The format of Dockerfile is [INSTRUCTION arguments] . Refer to the following description for INSTRUCTION.
|
Sponsored Link |
|