https://dev.to/s1ntaxe770r/how-to-setup-ssh-within-a-docker-container-i5i
를 참조해서 작업 중
https://tribal1012.tistory.com/323
(희안하게 해당 부분의 dockerfile 내용을 복사해서 사용할 경우 동작을 안 하고 오류가 남.)
0. Docker file 내용.
# apt 업데이트 후, openssh-server 설치
RUN apt update && apt install openssh-server sudo -y
# 사용자 (test) 추가.
RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1000 test
# 패스워드 변경
RUN echo 'test:test' | chpasswd
# 서비스 실행
RUN service ssh start
# SSH 포트 Open
EXPOSE 22
# 서비스 실행 한 거 아닌가? 또 필요한가?
CMD ["/usr/sbin/sshd","-D"]
1. Docker build
nitraqu@nitraqu-7c79:~/my_docker3$ sudo docker build -t ssh .
Sending build context to Docker daemon 2.048kB
Step 1/7 : FROM ubuntu:22.04
22.04: Pulling from library/ubuntu
2b55860d4c66: Pull complete
Digest: sha256:20fa2d7bb4de7723f542be5923b06c4d704370f0390e4ae9e1c833c8785644c1
Status: Downloaded newer image for ubuntu:22.04
---> 2dc39ba059dc
Step 2/7 : RUN apt update && apt install openssh-server sudo -y
---> Running in a4a74f5df50b
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Sending build context to Docker daemon 2.048kB
Step 1/7 : FROM ubuntu:22.04
22.04: Pulling from library/ubuntu
2b55860d4c66: Pull complete
Digest: sha256:20fa2d7bb4de7723f542be5923b06c4d704370f0390e4ae9e1c833c8785644c1
Status: Downloaded newer image for ubuntu:22.04
---> 2dc39ba059dc
Step 2/7 : RUN apt update && apt install openssh-server sudo -y
---> Running in a4a74f5df50b
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
2. Docker Container Run
nitraqu@nitraqu-7c79:~/my_docker3$ sudo docker run -p 22:22 ssh
2.1. Inspect Docker IP
nitraqu@nitraqu-7c79:~/my_docker3$ sudo docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 2ab73a16a8bc
172.17.0.2
3. SSH Connect to Server (Docker)
nitraqu@nitraqu-7c79:~/my_docker3$ ssh test@172.17.0.2
The authenticity of host '172.17.0.2 (172.17.0.2)' can't be established.
ED25519 key fingerprint is SHA256:XZ1vLpYWhjw1HXkyDKMsqdWQr06vCDYu+lRWPaYXFg4.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '172.17.0.2' (ED25519) to the list of known hosts.
test@172.17.0.2's password:
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-47-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.
To restore this content, you can run the 'unminimize' command.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
test@2ab73a16a8bc:~$



덧글
172.17.0.2