Docker : Use Dockerfile2021/08/30 |
Use Dockerfile and create Docker images automatically.
It is also useful for configuration management. |
|
[1] | For example, Create a Dockerfile that Apache2 is installed and started. |
root@dlp:~#
vi Dockerfile # create new FROM debian MAINTAINER ServerWorld <admin@srv.world> RUN apt-get update RUN apt-get -y install tzdata RUN apt-get -y install apache2 RUN echo "Dockerfile Test on Apache2" > /var/www/html/index.html EXPOSE 80 CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"] # build image ⇒ docker build -t [image name]:[tag] . root@dlp:~# docker build -t srv.world/debian-apache2:latest ./ Sending build context to Docker daemon 9.728kB Step 1/8 : FROM debian ---> fe3c5de03486 Step 2/8 : MAINTAINER ServerWorld <admin@srv.world> ---> Running in beed71c28d68 Removing intermediate container beed71c28d68 ---> 7327e34c8977 Step 3/8 : RUN apt-get update ---> Running in 4da51f3c7a0c ..... ..... Successfully built 35b4db75bde1 Successfully tagged srv.world/debian-apache2:latestroot@dlp:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE srv.world/debian-apache2 latest 35b4db75bde1 52 seconds ago 252MB srv.world/debian-nginx latest e07733601f30 5 minutes ago 210MB debian latest fe3c5de03486 12 days ago 124MB # run container root@dlp:~# docker run -d -p 8081:80 srv.world/debian-apache2 e65ae32ef0b4d3346f5bdf2ea3c23b2afd0b8c7bc59383abf8bd6926bd72b1f1root@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e65ae32ef0b4 srv.world/debian-apache2 "/usr/sbin/apachectl…" 8 seconds ago Up 7 seconds 0.0.0.0:8081->80/tcp stoic_ishizaka # verify accesses root@dlp:~# curl localhost:8081 Dockerfile Test on Apache2 |
The format of Dockerfile is [INSTRUCTION arguments] . Refer to the following description for INSTRUCTION.
|
Sponsored Link |
|