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.