SSH Login Docker container

Source: Internet
Author: User
Tags docker ps

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.