Docker : Use Dockerfile2023/04/27 |
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 20.99kB Step 1/8 : FROM ubuntu ---> 08d22c0ceb15 Step 2/8 : MAINTAINER ServerWorld <admin@srv.world> ---> Running in 0a226c7e4895 Removing intermediate container 0a226c7e4895 ---> 943e43d6e7a4 ..... ..... Successfully built 886e2f7307a1 Successfully tagged srv.world/ubuntu-apache2:latestroot@dlp:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE srv.world/ubuntu-apache2 latest 886e2f7307a1 3 minutes ago 235MB srv.world/ubuntu-nginx latest df0287c5017d 7 minutes ago 177MB ubuntu latest 08d22c0ceb15 7 weeks ago 77.8MB # run container root@dlp:~# docker run -d -p 8081:80 srv.world/ubuntu-apache2 7e5fbd168ce3ed1e5af58de4e9597b3f553cfb7d58568c02a1c32cc123dc6f26root@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7e5fbd168ce3 srv.world/ubuntu-apache2 "/usr/sbin/apachectl…" 10 seconds ago Up 8 seconds 0.0.0.0:8081->80/tcp, :::8081->80/tcp determined_keller # 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 |