1. Start a Docker container
# docker Run-t -I Ubuntu/ruby:v1/bin/bash
2, then in the container, install Openssh-server openssh-client
# apt-get Install openssh-server openssh-client
3. After completion, change the root password
# passwd
4. Exit the container and save the above changes
# Docker commit 3ea7a99a0025 Ubuntu/ruby:v2
5, stop, and delete the container just now
# docker stop [Container-id]
# docker RM [Container-id]
View Container ID
# docker Ps-a
View the Mirror list
# Docker Images
6. Start a new container in the background with the image you just saved
Docker run--name [Image-name]-i-t-P 50001:22 [Image-id]
Example: # Docker run-d-P 50001:22 ubuntu/ruby:v2/usr/sbin/sshd-d
7. SSH telnet to the container
# SSH [email protected]-P 50001
if you want to log in via SSH key, in the 2nd step, modify the/etc/ssh/sshd_config file to Rsaauthentication andthe values after pubkeyauthentication are changed to Yes, save.
upload the id_rsa.pub under Local. SSH to the id_rsa.pub in the container, and# mv/root/.ssh/id_rsa.pub/root/.ssh/authorized_keys, and then # chmod 600/root/.ssh/authorized_keys can be.
This article is from the "Dream to Reality" blog, please be sure to keep this source http://lookingdream.blog.51cto.com/5177800/1789767
SSH Login Docker container