Docker container run, generally cannot ssh, this container management brings trouble, below will explain how to create a docker image that supports SSH
Download the Ubuntu image from the dock hub first
Command: Docker pull Ubuntu
Create a new Ssh_ubuntu directory
Mkdir/ssh_ubuntu
Cd/ssh_ubuntu; Touch Dockerfile
VI Dockerfile
Dockerfile Content
From Ubuntu
Maintainer Lincoln_zhong
RUN apt-get Update
RUN apt-get install-y openssh-server sudo
RUN mkdir-p/var/run/sshd
RUN Sed-ri ' s/session required pam_loginuid.so/#session required pam_loginuid.so/g '/etc/pam.d/sshd
RUN Useradd Admin
RUN echo "Admin:admin" | chpasswd
RUN echo "admin all= (All) all" >>/etc/sudoers
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
650) this.width=650; "title=" capture. JPG "src=" http://s3.51cto.com/wyfs02/M02/6E/D4/wKiom1WJHhnAm7gXAAF7-nuigdQ137.jpg "alt=" Wkiom1wjhhnam7gxaaf7-nuigdq137.jpg "/>
Cd/ssh_ubuntu. Run Docker build-t Ssh_ubuntu. #ssh_ubuntu是镜像名称
Running Docker images
650) this.width=650; "title=" capture. JPG "src=" http://s3.51cto.com/wyfs02/M02/6E/D4/wKiom1WJHoqBBBSEAAKVgQxRIgE289.jpg "alt=" Wkiom1wjhoqbbbseaakvgqxrige289.jpg "/>
Run a Container test command: Docker run-d--name ssh_ubuntu_test-p 0.0.0.0:10000:22 Ssh_ubuntu
Command parsing
-D is started in daemon mode
--name Defining container Names
-P is a port that defines ports (above this means that 10000 ports on the local host (host) are mapped to the 22 ports of the container
650) this.width=650; "title=" capture. JPG "src=" http://s3.51cto.com/wyfs02/M00/6E/D4/wKiom1WJHzySz_p4AADelmZ_ODM797.jpg "alt=" wkiom1wjhzysz_p4aadelmz_ Odm797.jpg "/>
Container ssh_ubuntu_test run successfully, SSH login container Test command: SSH [email protected] host Ip-p 10000 I'm here for 10.10.1.181.
SSH [email protected]-P 10000
Test success
CentOS-built container dockerfile content for SSH support
This article is from the "Last Night Rain Wind Sudden" blog, please be sure to keep this source http://zxx287856774.blog.51cto.com/3417296/1664682
Create a Docker image that supports SSH