supervisor + ssh 알파인 도커 이미지 빌드

1 개요[ | ]

supervisor + ssh 알파인 도커 이미지 빌드 만들기

2 supervisord.conf 작성[ | ]

[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
[supervisord]
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock

[program:sshd]
command = /usr/sbin/sshd -D
→ 상단은 supervisor 자체에 대한 설정. supervisorctl을 사용하려면 이 정도는 설정해줘야 한다.
→ 하단은 supervisor로 구동할 프로그램에 대한 설정

3 Dockerfile 작성[ | ]

vi Dockerfile
FROM alpine:3.11
RUN set -x \
&& apk add --no-cache \
  openssh \
  supervisor \
&& mkdir -p /var/run/sshd \
&& sed 's/#PermitRootLogin.*/PermitRootLogin yes/' -i /etc/ssh/sshd_config \
&& sed 's/#PasswordAuthentication.*/PasswordAuthentication yes/' -i /etc/ssh/sshd_config \
&& echo 'root:P@ssw0rd' | chpasswd \
&& ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa \
&& ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa

COPY supervisord.conf /etc/
EXPOSE 22
CMD ["supervisord","-n","-c","/etc/supervisord.conf"]

4 docker build[ | ]

$ docker build -t alpine_supervisor_ssh .
Sending build context to Docker daemon  3.584kB
Step 1/5 : FROM alpine:3.11
 ---> a187dde48cd2
Step 2/5 : RUN set -x && apk add --no-cache   openssh   supervisor && mkdir -p /var/run/sshd && sed 's/#PermitRootLogin.*/PermitRootLogin yes/' -i /etc/ssh/sshd_config && sed 's/#PasswordAuthentication.*/PasswordAuthentication yes/' -i /etc/ssh/sshd_config && echo 'root:P@ssw0rd' | chpasswd && ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa && ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
 ---> Using cache
 ---> ba74d4e4dbc5
Step 3/5 : COPY supervisord.conf /etc/
 ---> Using cache
 ---> ffe9e0622630
Step 4/5 : EXPOSE 22
 ---> Using cache
 ---> 227bc9abb04c
Step 5/5 : CMD ["supervisord","-n","-c","/etc/supervisord.conf"]
 ---> Using cache
 ---> bd25f9eb3241
Successfully built bd25f9eb3241
Successfully tagged alpine_supervisor_ssh:latest

5 docker run[ | ]

$ docker run -d -P --name my_container alpine_supervisor_ssh
5b33c2e85ff7a89e64cb0ab0a5711d9138a31aa6fee7ecd9638f8acb19efeee0
$ docker ps
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                   NAMES
5b33c2e85ff7        alpine_supervisor_ssh   "supervisord -n -c /…"   8 seconds ago       Up 7 seconds        0.0.0.0:32785->22/tcp   my_container
$ docker logs my_container
2020-04-15 07:45:49,124 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
2020-04-15 07:45:49,132 INFO RPC interface 'supervisor' initialized
2020-04-15 07:45:49,132 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2020-04-15 07:45:49,133 INFO supervisord started with pid 1
2020-04-15 07:45:50,136 INFO spawned: 'sshd' with pid 7
2020-04-15 07:45:51,138 INFO success: sshd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

6 테스트[ | ]

$ ssh root@localhost -p 32785
The authenticity of host '[localhost]:32785 ([127.0.0.1]:32785)' can't be established.
RSA key fingerprint is SHA256:zRxsyKyD41rjT1OIGiQnYc+1kQ44tXXWo+JUGvr12RU.
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
Welcome to Alpine!

The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <http://wiki.alpinelinux.org/>.

You can setup the system with the command: setup-alpine

You may change this message by editing /etc/motd.

5b33c2e85ff7:~#
5b33c2e85ff7:~# ps -ef
PID   USER     TIME  COMMAND
    1 root      0:00 {supervisord} /usr/bin/python3 /usr/bin/supervisord -n -c /etc/supervis
    7 root      0:00 /usr/sbin/sshd -D
    8 root      0:00 sshd: root@pts/0
   10 root      0:00 -ash
   11 root      0:00 ps -ef
5b33c2e85ff7:~# supervisorctl status
sshd                             RUNNING   pid 7, uptime 0:01:25
5b33c2e85ff7:~# exit
Connection to localhost closed.
$

7 같이 보기[ | ]

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