Created
April 29, 2014 09:06
-
-
Save ruo91/11394722 to your computer and use it in GitHub Desktop.
Docker - Running an SSH service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@ruo91:~# nano Dockerfile | |
#------- Dockerfile start -------# | |
# | |
# Docker SSH Daemon | |
# | |
# 해당 Images를 선택 | |
# docker pull images-name과 같다고 보면 됌. | |
# 이미 이미지가 있다면 docker images 명령어로 해당 Image ID를 적으면 된다. | |
# | |
# 예제1) 이미지가 없을 경우 | |
# FROM ubuntu | |
# OR | |
# FROM ruo91/centos | |
# | |
# 예제2) 이미지가 이미 있을 경우 Image ID를 적으면 된다. | |
# FROM 74fe38d11401 | |
FROM 74fe38d11401 | |
MAINTAINER Yongbok Kim <[email protected]> | |
# 기존 미러 서버를 국내 서버로 변경 | |
RUN sed -i 's/archive.ubuntu.com/ftp.neowiz.com/g' /etc/apt/sources.list | |
# 최신버전으로 업데이트 후 SSH 및 필요 패키지 설치 | |
RUN apt-get update ; apt-get install -y openssh-server aptitude net-tools curl | |
# SSH 관련 설정 | |
RUN mkdir /var/run/sshd | |
RUN sed -i "/^[^#]*UsePAM/ s/.*/#&/" /etc/ssh/sshd_config | |
RUN echo "UsePAM no" >> /etc/ssh/sshd_config | |
# Root 비밀번호 설정 | |
RUN echo 'root:123456789' |chpasswd | |
# SSH 포트 설정 | |
# HostOS의 랜덤포트 -> Container 22번 포트를 바라보게 함. | |
# 즉, 외부에서 HostOS의 랜덤 포트로 접속하면 해당 Container에 접속 할수 있음. | |
# 더 자세한건 http://docs.docker.io/reference/builder/#expose 를 참고하자. | |
EXPOSE 22 | |
# SSH 실행 | |
CMD /usr/sbin/sshd -D | |
#------- Dockerfile end -------# | |
Dockerfile 생성 이후에 sshd 라는 이미지를 하나 빌드한다. | |
root@ruo91:~# docker build --rm -t sshd . | |
Uploading context 3.584 kB | |
Uploading context | |
Step 0 : FROM 74fe38d11401 | |
---> 74fe38d11401 | |
Step 1 : MAINTAINER Yongbok Kim <[email protected]> | |
---> Running in e014eef5327e | |
---> 930fa3d390d5 | |
Step 2 : RUN sed -i 's/archive.ubuntu.com/ftp.neowiz.com/g' /etc/apt/sources.list | |
---> Running in da2d95b9222a | |
---> 7e9b0e8d1c76 | |
Step 3 : RUN apt-get update ; apt-get install -y openssh-server | |
---> Running in e11bedea279f | |
Get:1 http://ftp.neowiz.com precise Release.gpg [198 B] | |
Get:2 http://ftp.neowiz.com precise-updates Release.gpg [198 B] | |
Get:3 http://ftp.neowiz.com precise-security Release.gpg [198 B] | |
Get:4 http://ftp.neowiz.com precise Release [49.6 kB] | |
Get:5 http://ftp.neowiz.com precise-updates Release [49.6 kB] | |
Get:6 http://ftp.neowiz.com precise-security Release [49.6 kB] | |
Get:7 http://ftp.neowiz.com precise/main Sources [1175 kB] | |
Get:8 http://ftp.neowiz.com precise/restricted Sources [5306 B] | |
Get:9 http://ftp.neowiz.com precise/universe Sources [6239 kB] | |
....... Blah blah....... | |
.........................Blah blah...... | |
................................................ | |
ldconfig deferred processing now taking place | |
---> 0bfc548c5b70 | |
Step 4 : RUN mkdir /var/run/sshd | |
---> Running in 5fe2ff192daf | |
---> fbb91b469aa2 | |
Step 5 : RUN sed -i "/^[^#]*UsePAM/ s/.*/#&/" /etc/ssh/sshd_config | |
---> Running in 5928b6e26d12 | |
---> aad27b0563f6 | |
Step 6 : RUN echo "UsePAM no" >> /etc/ssh/sshd_config | |
---> Running in 2c7b1bdf9d40 | |
---> 619ba6ad2a74 | |
Step 7 : RUN echo 'root:123456789' |chpasswd | |
---> Running in d9aeccface23 | |
---> 52c2268728e5 | |
Step 8 : EXPOSE 4000 22 | |
---> Running in deb95bfe5566 | |
---> 4edce08a3ca7 | |
Step 9 : CMD /usr/sbin/sshd -D | |
---> Running in fa21cdb8ca07 | |
---> bbeeb5952a8f | |
Successfully built bbeeb5952a8f | |
Removing intermediate container e014eef5327e | |
Removing intermediate container da2d95b9222a | |
Removing intermediate container e11bedea279f | |
Removing intermediate container 5928b6e26d12 | |
Removing intermediate container deb95bfe5566 | |
Removing intermediate container fa21cdb8ca07 | |
Removing intermediate container 5fe2ff192daf | |
Removing intermediate container 2c7b1bdf9d40 | |
Removing intermediate container d9aeccface23 | |
이제 sshd 라는 이름으로 하나 생성 되었다. | |
root@ruo91:~/docker# docker images | |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE | |
sshd latest bbeeb5952a8f 3 minutes ago 338.9 MB | |
해당 이미지를 실행 하자. | |
root@ruo91:~/docker# docker run -d -P --name ubuntu_12.04_LTS_SSHD sshd | |
0089aa15a968ddaa33f8931759dcb7028fed46f8bf0a840ae65869d577884532 | |
HostOS의 49155번의 포트가 해당 Container의 22번 포트를 바라보고 있는걸 알수 있다. | |
root@ruo91:~# docker ps | |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
0089aa15a968 sshd:latest /bin/sh -c '/usr/sbi 9 minutes ago Up 8 minutes 0.0.0.0:49155->22/tcp ubuntu_12.04_LTS | |
실제로 접속해보면 잘 된다. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment