Docker : Use Dockerfile2024/06/13 |
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 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 5.3s (4/8) docker:default => [internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 297B 0.0s => [internal] load .dockerignore 0.1s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/ubuntu:latest 0.0s => [1/5] FROM docker.io/library/ubuntu 0.0s => [2/5] RUN apt-get update 5.2s ..... ..... [+] Building 29.6s (9/9) FINISHED docker:default => [internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 297B 0.0s => [internal] load .dockerignore 0.1s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/ubuntu:latest 0.0s => [1/5] FROM docker.io/library/ubuntu 0.0s => [2/5] RUN apt-get update 7.7s => [3/5] RUN apt-get -y install tzdata 4.7s => [4/5] RUN apt-get -y install apache2 16.3s => [5/5] RUN echo "Dockerfile Test on Apache2" > /var/www/html/index.htm 0.3s => exporting to image 0.4s => => exporting layers 0.4s => => writing image sha256:d987da01ec6c2950e15b8ba662834d235bdcab141c181 0.0s => => naming to srv.world/ubuntu-apache2:latest 0.0sroot@dlp:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE srv.world/ubuntu-apache2 latest d987da01ec6c About a minute ago 225MB srv.world/ubuntu-nginx latest f3f6605bb20c 15 minutes ago 123MB ubuntu latest 17c0145030df 13 days ago 76.2MB # run container root@dlp:~# docker run -d -p 8081:80 srv.world/ubuntu-apache2 88c8b459e9ff03d466924c8bb03f23ac5ea27b7b638a7ba4193b2c7e281b9787root@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 88c8b459e9ff srv.world/ubuntu-apache2 "/usr/sbin/apachectl…" 14 seconds ago Up 13 seconds 0.0.0.0:8081->80/tcp, :::8081->80/tcp naughty_khayyam # 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 |