Dockerfileとは?

やりたいこと

monitimg.png

準備

Dockerfile

# FROM             (1)   : base docker image
# MAINTAINER       (1)   :
# RUM <cmd>        (0.n) : Command. You can use both simple command style and
#                          the exec form style ["xx","-y","-z"].
# ADD <src> <dest> (0.n) : Copy files from host to gest
# EXPOSE <port>    (0.n) : Expose port infos for container users. It's not port
#                          forward setting.
# CMD <cmd>        (1)   : Service command.(["/usr/sbin/apachectl","-DFOREGROUND"])
#                          You should use the exec form style ["xx","-y","-z"].
# ENTRYPOINT <cmd> (0.1) : Prefix of service command. ("/usr/sbin/apachectl")
#                          $ docker run -p 8080:80 -d cent6_apache -DFOREGROUND
#                          => call "/usr/sbin/apachectl -DFOREGROUND" on guest.
# ENV <key> <val>  (0.n) :
# VOLUME <dir>     (0.n) : shared directory
# WORKDIR <dir>    (0.1) :
# ONBUILD RUN ...  (0.n) : will execute during child image building (this image is
# ONBUILD ADD ...  (0.n) : specified as FROM).
#
# Each line is commit as layer of Unit FS. Caution, max layer is 127.

# Pull base image.
FROM centos:centos6

MAINTAINER Atsushi HONDOH <kagyuu@hondou.homedns.org>

## Proxy
# ENV http_proxy http://foo%40bar.com:password@proxy.bar.com:3124/
# ENV https_proxy http://foo%40bar.com:password@proxy.bar.com:3124/

## Install monit and sshd
RUN rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
RUN yum -y update
RUN yum -y install passwd openssh openssh-server openssh-clients sudo monit

## Operator user
RUN useradd docker
RUN passwd -f -u docker
RUN usermod -G wheel docker

## Setup sudoers
RUN echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers

## Set up SSH
RUN mkdir -p /home/docker/.ssh; chown docker /home/docker/.ssh; chmod 700 /home/docker/.ssh
ADD authorized_keys /home/docker/.ssh/authorized_keys

RUN chown docker /home/docker/.ssh/authorized_keys
RUN chmod 600 /home/docker/.ssh/authorized_keys

RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config
RUN sed -ri 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config
RUN sed -ri 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config

## Init SSHD
RUN /etc/init.d/sshd start &&\
/etc/init.d/sshd stop

## Setup monit
RUN sed -ri 's/use address localhost/use address 0.0.0.0/g' /etc/monit.conf
RUN sed -ri 's/allow localhost/#allow localhost/g' /etc/monit.conf

ADD ssh.conf /etc/monit.d/ssh.conf

## Expose ports
## 22   : ssh
## 2812 : monit web console
EXPOSE 22 2812

## Execute monit
CMD ["/usr/bin/monit","-I"]

docker build

core@localhost ~/git/DockerExam/cent6_ssh $ docker build -t atsushi/cent6_monit_ssh ./
Sending build context to Docker daemon  12.8 kB
Sending build context to Docker daemon
Step 0 : FROM centos:centos6
 ---> b1bd49907d55
Step 1 : MAINTAINER Atsushi HONDOH <kagyuu@hondou.homedns.org>
 ---> 73dd39abd0da
Step 2 : RUN rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
 ---> b7e1c2986df2
Step 3 : RUN yum -y update
 ---> 90383b83723e
Step 4 : RUN yum -y install passwd openssh openssh-server openssh-clients sudo monit
 ---> 0af9aabfeaa5
Step 5 : RUN useradd docker
 ---> d087b332f891
Step 6 : RUN passwd -f -u docker
 ---> 946e4483f21f
Step 7 : RUN usermod -G wheel docker
 ---> 79096ff3f274
Step 8 : RUN echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers
 ---> b320bdb5e8c6
Step 9 : RUN mkdir -p /home/docker/.ssh; chown docker /home/docker/.ssh; chmod 700 /home/docker/.ssh
 ---> 5e071b7eecdf
Step 10 : ADD authorized_keys /home/docker/.ssh/authorized_keys
 ---> 3dc25cd4fd7e
Step 11 : RUN chown docker /home/docker/.ssh/authorized_keys
 ---> 14066bb6bb2c
Step 12 : RUN chmod 600 /home/docker/.ssh/authorized_keys
 ---> 2fdf021a1bd0
Step 13 : RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
 ---> 9b19879ca517
Step 14 : RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config
 ---> 39d043b35e23
Step 15 : RUN sed -ri 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config
 ---> d521d63867d1
Step 16 : RUN sed -ri 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
 ---> cb23671f25f9
Step 17 : RUN /etc/init.d/sshd start &&/etc/init.d/sshd stop
 ---> b5f833d07457
Step 18 : RUN sed -ri 's/use address localhost/use address 0.0.0.0/g' /etc/monit.conf
 ---> 1f24fa7d7da5
Step 19 : RUN sed -ri 's/allow localhost/#allow localhost/g' /etc/monit.conf
 ---> 14cf11694cbf
Step 20 : ADD ssh.conf /etc/monit.d/ssh.conf
 ---> 3ffa6f3b9e26
Step 21 : EXPOSE 22 2812
 ---> Running in 8857657ec67e
Successfully built 43db0564a524

できた

core@localhost ~/git/DockerExam/cent6_ssh $ docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
atsushi/volume             latest              aaf0c39f6953        22 hours ago        226.4 MB
atsushi/cent6_monit_ssh    latest              43db0564a524        23 hours ago        452.9 MB
atsushi/ubuntu_monit_ssh   latest              c53db8fef482        24 hours ago        409.9 MB
ubuntu                     14.10               75204fdb260b        3 weeks ago         226.4 MB
cent6_monit                latest              42c1c6908ea4        3 weeks ago         324.2 MB
cent6_apache               latest              633e8b36e083        3 weeks ago         300.6 MB
centos                     centos6             b1bd49907d55        5 weeks ago         212.5 MB
centos                     latest              b157b77b1a65        5 weeks ago         243.7 MB

実行してみる

core@localhost ~/git/DockerExam/cent6_ssh $ docker run -p 12812:2812 -p 10022:22 -d atsushi/cent6_monit_ssh
57b3d5c16134d0952c291288639a223ca84008ae2d34d5cd28a5b5a396ec544e
monit.png

Docker


添付ファイル: filemonitimg.png 2399件 [詳細] filemonit.png 2193件 [詳細] filefirefox.png 1189件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2014-09-07 (日) 21:14:16 (3743d)
Short-URL:
ISBN10
ISBN13
9784061426061