Docker : Use Dockerfile2022/09/08 |
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 ubuntu 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/ubuntu-apache2:latest ./ Sending build context to Docker daemon 27.14kB Step 1/8 : FROM ubuntu ---> 2dc39ba059dc Step 2/8 : MAINTAINER ServerWorld <admin@srv.world> ---> Running in de1d1b875fe0 Removing intermediate container de1d1b875fe0 ---> e25181251546 Step 3/8 : RUN apt-get update ---> Running in 836063f687fc ..... ..... Step 8/8 : CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"] ---> Running in 31d5749415a9 Removing intermediate container 31d5749415a9 ---> b7891f747bd5 Successfully built b7891f747bd5 Successfully tagged srv.world/ubuntu-apache2:latestroot@dlp:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE srv.world/ubuntu-apache2 latest b7891f747bd5 About a minute ago 227MB srv.world/ubuntu-nginx latest 51f5190bb9d9 6 minutes ago 170MB ubuntu latest 2dc39ba059dc 5 days ago 77.8MB # run container root@dlp:~# docker run -d -p 8081:80 srv.world/ubuntu-apache2 60784c2019f6fc53169367c51b4aaf75ed7fae1cdbf107bbccd95bc40c29719froot@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 60784c2019f6 srv.world/ubuntu-apache2 "/usr/sbin/apachectl…" 8 seconds ago Up 8 seconds 0.0.0.0:8081->80/tcp, :::8081->80/tcp nifty_pascal # 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 |
|