SSH remote connection to Docker in container

Source: Internet
Author: User
Tags ssh docker ps docker run

Due to work needs, to connect container remotely, the local machine is Windows, the following is the resolution steps:

1. Environment

Local: Windows

Docker version 1.12

Remote: Container in Docker (Ubuntu)


2. Container Installing the SSH service

First enter the container and proceed as follows:

① Installing SSH

sudo apt-get install openssh-server #安装ssh服务器 service
SSH status # view SSH service startup condition service
ssh start # start SSH service
② configure SSH to allow root login

Vi/etc/ssh/sshd_config
Change the value of Permitrootlogin from Withoutpassword to Yes

③ Restart SSH Service

Service SSH Restart # restart SSH Services


3. Save Container Image

Also open Docker Quickstart Terminal, save image

Docker PS #查看正在运行的container
* * Find the container ID of the container you want to save, assuming xxxxxx**
Docker commit xxxxxxxx tomjerry/ Foobar
(Note: Tomjerry/foobar is the name of the new image to be saved, can be arbitrarily written)


4. Re-run container

Docker Run-it-p 50001:22 Tomjerry/foobar/bin/bash
Service SSH Start
Note the-P 50,001:22, which means that the 50001 port of Docker and the 22 port of container are bound, so that accessing Docker 50001 is equivalent to accessing container's 22 port


5. SSH Connection Container
You can connect using SSH client tools such as Xshell or putty container

First assume that the IP of each party is as follows:

Local Windows ip:192.168.99.1
docker ip:192.168.99.100
container ip:172.17.0.3
Then, you want to remote container, you want to access the following address:

SSH 192.168.99.100:50001

This way, by accessing Docker's 50001 port, it magically indirectly connects to the container 22 port, thus achieving the purpose of SSH connection 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.