Docker : Use Dockerfile2023/06/22 |
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 18.43kB Step 1/8 : FROM debian ---> 49081a1edb0b Step 2/8 : MAINTAINER ServerWorld <admin@srv.world> ---> Running in 96b14acc8751 Removing intermediate container 96b14acc8751 ---> 8c66e9445174 Step 3/8 : RUN apt-get update ..... ..... Removing intermediate container 80ec238dedae ---> 431c51e7819a Successfully built 431c51e7819a Successfully tagged srv.world/debian-apache2:latestroot@dlp:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE srv.world/debian-apache2 latest 431c51e7819a About a minute ago 252MB srv.world/debian-nginx latest 5a202ab0ab76 6 minutes ago 153MB debian latest 49081a1edb0b 9 days ago 116MB # run container root@dlp:~# docker run -d -p 8081:80 srv.world/debian-apache2 bc96f9eae7cf186114e33599f1c95704b9545faa36d22ae4743864f97432014broot@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bc96f9eae7cf srv.world/debian-apache2 "/usr/sbin/apachectl…" 10 seconds ago Up 9 seconds 0.0.0.0:8081->80/tcp, :::8081->80/tcp hungry_mahavira # 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 |