Created
July 4, 2014 06:45
-
-
Save myaaaaa-chan/57535e539b668772d2e2 to your computer and use it in GitHub Desktop.
sshでログインできるDockerfile
This file contains hidden or 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
| FROM centos | |
| MAINTAINER myaaaaa | |
| #Install Packages | |
| RUN yum update -y | |
| RUN yum install -y passwd openssh openssh-server openssh-clients sudo | |
| # Root password | |
| RUN echo "root:rootroot" | chpasswd | |
| ## Create user | |
| RUN useradd docker | |
| RUN passwd -f -u docker | |
| ## 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 | |
| ## setup sudoers | |
| RUN echo "docker ALL=(ALL) ALL" >> /etc/sudoers.d/doc | |
| ## Set up SSHD config | |
| RUN sed -ri 's/#PermitRootLogin yes/PermitRootLogin yes/g' /etc/ssh/sshd_config | |
| 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 | |
| ## Init SSHD | |
| RUN /etc/init.d/sshd start | |
| RUN /etc/init.d/sshd stop |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
docker run -d -p 22 centos:sshd /usr/sbin/sshd -D
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bf3e22a79057 centos:sshd /usr/sbin/sshd -D 4 seconds ago Up 3 seconds 0.0.0.0:49153->22/tcp elegant_franklin
ssh docker@localhost -p 49153