Docker : Use Dockerfile2017/07/30 |
Use Dockerfile and create Docker images automatically.
It is also useful for configuration management. |
|
[1] | For example, Create a Dockerfile to install httpd and sshd and also install Supervisor to control multiple services on a Container. |
[root@dlp ~]#
vi Dockerfile # create new FROM fedora MAINTAINER ServerWorld <admin@srv.world> RUN dnf -y install openssh-server httpd 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=/usr/sbin/sshd -D autostart=true autorestart=true [program:httpd] command=/usr/sbin/httpd -D FOREGROUND 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 17.92 kB Step 1/10 : FROM fedora ---> 7f17e6b4a386 Step 2/10 : MAINTAINER ServerWorld <admin@srv.world> ---> Running in d67b7462d08d ---> 3d33461d5d8f ..... ..... Removing intermediate container e73ed57dd718 Successfully built 40244c18250d[root@dlp ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE web_server latest 40244c18250d 11 seconds ago 461 MB srv.world/fedora_httpd latest 441834eaabe4 3 hours ago 478 MB registry.fedoraproject.org/fedora latest 7f17e6b4a386 4 weeks ago 232 MB # run Container on background [root@dlp ~]# docker run -d -p 2022:22 -p 8081:80 web_server [root@dlp ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS 2dac0079a358 web_server "/usr/bin/su.. 5 seconds Up 4 sec 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@2dac0079a358 ~]# |
The format of Dockerfile is [INSTRUCTION arguments] . Refer to the following description for INSTRUCTION.
|
Sponsored Link |
|