Docker : Use Dockerfile2026/05/08 |
|
Use Dockerfile and create Docker images automatically. |
|
| [1] | For example, Create a Dockerfile that Apache2 is installed and started. |
|
root@dlp:~#
apt -y install docker-buildx
root@dlp:~#
vi Dockerfile # create new FROM ubuntu 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/ubuntu-apache2:latest ./ [+] Building 1.1s (9/9) FINISHED docker:default => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 305B 0.0s => [internal] load metadata for docker.io/library/ubuntu:latest 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [1/5] FROM docker.io/library/ubuntu:latest@sha256:f3d28607ddd78734bb7f71f117f3c6706c666b8b76cbff7c9ff6e5718d46ff64 0.0s => => resolve docker.io/library/ubuntu:latest@sha256:f3d28607ddd78734bb7f71f117f3c6706c666b8b76cbff7c9ff6e5718d46ff64 0.0s => CACHED [2/5] RUN apt-get update 0.0s => CACHED [3/5] RUN apt-get -y install tzdata 0.0s => CACHED [4/5] RUN apt-get -y install apache2 0.0s => CACHED [5/5] RUN echo "Dockerfile Test on Apache2" > /var/www/html/index.html 0.0s => exporting to image 1.0s => => exporting layers 0.0s => => exporting manifest sha256:df9756eaa0adea8deb22be4b35b58b1551ff9ef552f22321f66b715cc448ee74 0.0s => => exporting config sha256:d7556517944c60c9f20e5c39f9a08720d9f4f9ba2d3ea280b1e22f84b5b09231 0.0s => => exporting attestation manifest sha256:d128efc958573f831fa519ca3c1dc265d676c987f9a23e4eff6520a8f237efb0 0.0s => => exporting manifest list sha256:c6da801438b04c9cc6ce186061601eb255c38317ae2018e0e33575e8b3503f91 0.0s => => naming to srv.world/ubuntu-apache2:latest 0.0s => => unpacking to srv.world/ubuntu-apache2:latestroot@dlp:~# docker images IMAGE ID DISK USAGE CONTENT SIZE EXTRA srv.world/ubuntu-apache2:latest c6da801438b0 340MB 92.8MB srv.world/ubuntu-nginx:latest 305dfeaadebc 227MB 69.9MB U ubuntu:latest f3d28607ddd7 160MB 45.3MB U # run container root@dlp:~# docker run -d -p 8081:80 srv.world/ubuntu-apache2 735e80df684c837affaefe93fc5e56e0813239969092c0dfe9859eb11f74e0ebroot@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 735e80df684c srv.world/ubuntu-apache2 "/usr/sbin/apachectl…" 16 seconds ago Up 15 seconds 0.0.0.0:8081->80/tcp, [::]:8081->80/tcp condescending_boyd # 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 |
|
|