Docker : Use Dockerfile2017/08/03 |
Use Dockerfile and create Docker images automatically.
It is also useful for configuration management. |
|
[1] | For example, Create a Dockerfile to install apache2 and sshd and also install Supervisor to control multiple services on a Container. |
root@dlp:~#
vi Dockerfile # create new FROM debian MAINTAINER ServerWorld <admin@srv.world> RUN apt-get update; apt-get -y install ssh apache2 supervisor RUN echo "Hello DockerFile World" > /var/www/html/index.html RUN mkdir /root/.ssh; chown root. /root/.ssh; chmod 700 /root/.ssh RUN ssh-keygen -A ADD supervisord.conf /etc/supervisord.conf ADD .ssh/id_rsa.pub /root/.ssh/authorized_keys EXPOSE 22 80 CMD ["/usr/bin/supervisord"] [supervisord] nodaemon=true [program:sshd] command=/etc/init.d/ssh start autostart=true autorestart=true [program:httpd] command=/etc/init.d/apache2 start autostart=true autorestart=true # generate SSH key root@dlp:~# ssh-keygen -q -N "" -f /root/.ssh/id_rsa
# build image ⇒ docker build -t [image name]:[tag] . root@dlp:~# docker build -t web_server:latest . Sending build context to Docker daemon 27.65kB Step 1/10 : FROM debian ---> a20fd0d59cf1 Step 2/10 : MAINTAINER ServerWorld < admin@srv.world> ---> Using cache ---> 526dda9559bd ..... ..... Successfully built 3c4e390e6c8e Successfully tagged web_server:latestroot@dlp:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE web_server latest 3c4e390e6c8e 19 seconds ago 296MB srv.world/deb_apache2 latest 8efc6944bf8d 2 days ago 219MB debian latest a20fd0d59cf1 10 days ago 100MB # run Container on background root@dlp:~# docker run -d -p 2022:22 -p 8081:80 web_server 17d282b0a8d9cc4aaafaa2d07c22971fb892c420bc3d942f040b5505a1fa3a6f root@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS 17d282b0a8d9 web_server "/usr/bin/su.. 13 secon Up 11 seco 0.0.0.0:2022->22/tcp, 0.0.0.0:8081->80/tcp.. # verify accesses root@dlp:~# curl localhost:8081 Hello DockerFile World root@dlp:~# ssh -p 2022 localhost root@17d282b0a8d9:~# |
The format of Dockerfile is [INSTRUCTION arguments] . Refer to the following description for INSTRUCTION.
|
Sponsored Link |
|