Docker : Use Dockerfile2022/07/29 |
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 quay.io/centos/centos:stream9 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 21.5kB Step 1/7 : FROM quay.io/centos/centos:stream9 ---> 61674c24ebbf Step 2/7 : MAINTAINER ServerWorld <admin@srv.world> ---> Running in e126c7956669 Removing intermediate container e126c7956669 ---> 441ed9ada006 Step 3/7 : RUN dnf -y install httpd ---> Running in 68d9a9ea50fb ..... ..... Successfully built db5fee1dd895 Successfully tagged srv.world/centos-httpd:latest[root@dlp ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE srv.world/centos-httpd latest db5fee1dd895 About a minute ago 257MB srv.world/centos-nginx latest 7fd90c511873 7 minutes ago 251MB quay.io/centos/centos stream9 61674c24ebbf 30 hours ago 152MB # run container [root@dlp ~]# docker run -d -p 8081:80 srv.world/centos-httpd 40b410e2dd655ff89b25842c613133c38729fe4be6d3b3066ed765b2b3d16b88[root@dlp ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 40b410e2dd65 srv.world/centos-httpd "/usr/sbin/httpd -D …" 16 seconds ago Up 16 seconds 0.0.0.0:8081->80/tcp, :::8081->80/tcp dreamy_morse # 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 |