supervisor + ssh + cron 데비안 도커 이미지 빌드

1 개요[ | ]

supervisor + ssh + cron 데비안 도커 이미지 빌드

2 Dockerfile 작성[ | ]

vi Dockerfile
FROM debian:10-slim
RUN set -x \
&& apt-get update -y \
&& apt-get install -y --no-install-recommends \
  cron \
  supervisor \
  openssh-server \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir /var/run/sshd \
&& echo 'root:P@ssw0rd' | chpasswd \
&& sed 's/#PermitRootLogin.*/PermitRootLogin yes/g' -i /etc/ssh/sshd_config \
&& mkdir -p /var/log/supervisor \
&& echo '* * * * * date >> /mycron1.txt' > /etc/cron.d/mycron1 \
&& crontab /etc/cron.d/mycron1 \
&& echo "[program:sshd]\n\
command=/usr/sbin/sshd -D\n\
[program:cron]\n\
command=cron -f" > /etc/supervisor/conf.d/supervisord.conf
EXPOSE 22
CMD ["/usr/bin/supervisord","-n"]

3 docker build[ | ]

$ docker build -t debian_supervisor_ssh_cron .
Sending build context to Docker daemon   2.56kB
Step 1/4 : FROM debian:10-slim
10-slim: Pulling from library/debian
c499e6d256d6: Pull complete 
Digest: sha256:76c15066d7db315b42dc247b6d439779d2c6466f7dc2a47c2728220e288fc680
Status: Downloaded newer image for debian:10-slim
 ---> 8e022c70c28b
Step 2/4 : RUN set -x && apt-get update -y && apt-get install -y --no-install-recommends   cron   supervisor   openssh-server && rm -rf /var/lib/apt/lists/* && mkdir /var/run/sshd && echo 'root:P@ssw0rd' | chpasswd && sed 's/#PermitRootLogin.*/PermitRootLogin yes/g' -i /etc/ssh/sshd_config && mkdir -p /var/log/supervisor && echo '* * * * * date >> /mycron1.txt' > /etc/cron.d/mycron1 && crontab /etc/cron.d/mycron1 && echo "[program:sshd]\ncommand=/usr/sbin/sshd -D\n[program:cron]\ncommand=cron -f" > /etc/supervisor/conf.d/supervisord.conf
 ---> Running in 20ff54479165
+ apt-get update -y
Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:2 http://deb.debian.org/debian buster InRelease [122 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [49.3 kB]
... (생략)
Step 3/4 : EXPOSE 22
 ---> Running in 60321ce291f6
Removing intermediate container 60321ce291f6
 ---> e514eaab17e2
Step 4/4 : CMD ["/usr/bin/supervisord","-n"]
 ---> Running in b8d8abc035ce
Removing intermediate container b8d8abc035ce
 ---> 5bbc08b0ac8d
Successfully built 5bbc08b0ac8d
Successfully tagged debian_supervisor_ssh_cron:latest

4 docker run[ | ]

$ docker run -d -P --name my_container debian_supervisor_ssh_cron
1072dbb6fa13e0813f4121ebcebf17e2a5a13cbb07e8e7ea714c46380a64e8d8
$ docker ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                   NAMES
1072dbb6fa13        debian_supervisor_ssh_cron   "/usr/bin/supervisor…"   10 seconds ago      Up 8 seconds        0.0.0.0:32769->22/tcp   my_container

5 테스트[ | ]

$ ssh root@localhost -p 32769
The authenticity of host '[localhost]:32769 ([127.0.0.1]:32769)' can't be established.
ECDSA key fingerprint is SHA256:HasA1GyPpgy04yN5gR8KBVS3AtTQU3od9IlR5bj0mj0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:32769' (ECDSA) to the list of known hosts.
root@localhost's password: P@ssw0rd
Linux 1072dbb6fa13 4.19.112+ #1 SMP Sat Apr 4 00:12:45 PDT 2020 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@1072dbb6fa13:~#
root@1072dbb6fa13:~# ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 10:23 ?        00:00:00 /usr/bin/python2 /usr/bin/supervisord -n
root           8       1  0 10:23 ?        00:00:00 cron -f
root           9       1  0 10:23 ?        00:00:00 /usr/sbin/sshd -D
root          12       9  0 10:23 ?        00:00:00 sshd: root@pts/0
root          18      12  0 10:23 pts/0    00:00:00 -bash
root          25      18  0 10:24 pts/0    00:00:00 ps -ef
root@1072dbb6fa13:~# supervisorctl status
cron                             RUNNING   pid 8, uptime 0:01:31
sshd                             RUNNING   pid 9, uptime 0:01:31
root@1072dbb6fa13:~# crontab -l
* * * * * date >> /mycron1.txt
root@1072dbb6fa13:~# cat /mycron1.txt 
Wed Apr 15 10:24:01 UTC 2020
Wed Apr 15 10:25:01 UTC 2020
root@1072dbb6fa13:~# exit
logout
Connection to localhost closed.
$

6 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}