Docker : Use Dockerfile
2020/06/02 |
Use Dockerfile and create Docker images automatically.
It is also useful for configuration management. |
|
[1] | For example, Create a Dockerfile that Nginx 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 nginx RUN echo "Dockerfile Test on Nginx" > /var/www/html/index.html EXPOSE 80 CMD ["/usr/sbin/nginx", "-g", "daemon off;"] # build image ⇒ docker build -t [image name]:[tag] . root@dlp:~# docker build -t nginx_server:latest ./ Sending build context to Docker daemon 25.6kB Step 1/7 : FROM ubuntu ---> 1d622ef86b13 Step 2/7 : MAINTAINER ServerWorld <admin@srv.world> ---> Using cache ---> f0e63877306b Step 3/7 : RUN apt update ---> Running in bcd6fcaa6ded ..... ..... Successfully built 2d5672bca343 Successfully tagged nginx_server:latestroot@dlp:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx_server latest 2d5672bca343 About a minute ago 155MB srv.world/ubuntu_nginx latest d30733d4f315 About an hour ago 155MB ubuntu latest 1d622ef86b13 5 weeks ago 73.9MB # run container root@dlp:~# docker run -d -p 8081:80 nginx_server b030bf10dab33c79b80ac3910380dcf98cc7fcf1cefa3b95a2f5d96d59db6413root@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b030bf10dab3 nginx_server "/usr/sbin/nginx -g …" 9 seconds ago Up 8 seconds 0.0.0.0:8081->80/tcp cranky_kilby # verify accesses root@dlp:~# curl localhost:8081 Dockerfile Test on Nginx |
The format of Dockerfile is [INSTRUCTION arguments] . Refer to the following description for INSTRUCTION.
|