Docker : Use Dockerfile2025/08/26 |
|
Use Dockerfile and create Docker images automatically. |
|
| [1] | For example, Create a Dockerfile that Apache2 is installed and started. |
|
root@dlp:~#
vi Dockerfile # create new FROM debian LABEL 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 ./ => [1/5] FROM docker.io/library/debian:latest => [2/5] RUN apt-get update => [3/5] RUN apt-get -y install tzdata => [4/5] RUN apt-get -y install apache2 => [5/5] RUN echo "Dockerfile Test on Apache2" > /var/www/html/index.html => exporting to image => => exporting layers => => writing image sha256:8101aa733631a4aad6bf36cb571fc775f42473d1a0e82bea814f78c4a57d5da3 => => naming to srv.world/debian-apache2:latestroot@dlp:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE srv.world/debian-apache2 latest 8101aa733631 57 seconds ago 226MB srv.world/debian-nginx latest 64fe195a727d 12 minutes ago 153MB debian latest 047bd8d81940 2 weeks ago 120MB # run container root@dlp:~# docker run -d -p 8081:80 srv.world/debian-apache2 3ec383b45bad97b2db381eb4e907c14fddd7203addc0f12b5546ced741dc7a84root@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3ec383b45bad srv.world/debian-apache2 "/usr/sbin/apachectl…" 10 seconds ago Up 9 seconds 0.0.0.0:8081->80/tcp, :::8081->80/tcp affectionate_pike # 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 |
|
|