Docker : Use Dockerfile2021/05/13 |
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 25.6kB Step 1/8 : FROM ubuntu ---> 7e0aa2d69a15 Step 2/8 : MAINTAINER ServerWorld <admin@srv.world> ---> Using cache ---> a2fa80a6247c Step 3/8 : RUN apt-get update ---> Using cache ---> 676629fe1237 ..... ..... Successfully built 84bcc150feb9 Successfully tagged srv.world/ubuntu-apache2:latestroot@dlp:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE srv.world/ubuntu-apache2 latest 84bcc150feb9 3 minutes ago 216MB srv.world/ubuntu-nginx latest 8f1fbe417eb2 14 minutes ago 160MB ubuntu latest 7e0aa2d69a15 2 weeks ago 72.7MB # run container root@dlp:~# docker run -d -p 8081:80 srv.world/ubuntu-apache2 91f835c52b0f2b6f71b7deb0591e0bef5cdd70c5fb0e817f69d905c9a0ae83ccroot@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 91f835c52b0f srv.world/ubuntu-apache2 "/usr/sbin/apachectl…" 8 seconds ago Up 7 seconds 0.0.0.0:8081->80/tcp ecstatic_pare # 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 |
|