Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Ssh connect docker server details


May 30, 2021 Article blog


Table of contents


When the editor first touched docker, it was true, watching the half-day tutorial will not make, but now at least understand that docker is a container, which can put a variety of software, put ubuntu, this container can be seen as ubuntu used in other environments, today to show small partners how to use ssh to connect docket server.

Mainly talk about how to create a docker service that others can use through ssh connection (in the case of ubuntu)

Create a container

If a mirror is required, small partners who have used mirror installations such as ubuntu should understand that if not, one can be downloaded via the docker pull image name

Create a container in the ubuntu image and map the docker server's 50003 port to the container's 22 ports

docker run -it -d -p 50003:22 ubuntu

That's when we use docker ps to see that our container is already started

 Ssh connect docker server details1

Enter the container through the ID

docker exec -it a9cbce70127f /bin/bash

That's when we got into the container, which is in the ubuntu environment

 Ssh connect docker server details2

Install ssh server

apt-get update
apt-get install passwd
apt-get install openssh-server

Installing the ssh service here will let you choose your time zone, just select it digitally, and I'll use 6 31

Tips: If you use a command and report that the command cannot be found, you can install the command directly using the apt-get install command name

Set the root password with the passwd command

 Ssh connect docker server details3

Start the ssh service

service ssh start

You can see if the service is started by ps -e |grep ssh

Modify the profile

Open the profile through the vim editor

vim /etc/ssh/sshd_config

Write the following in the profile (comment)

PubkeyAuthentication yes                #启用公钥私钥配对认证方式
AuthorizedKeysFile .ssh/authorized_keys #公钥文件路径
PermitRootLogin yes                     #root能使用ssh登录

Here if the prompt does not have a vim command on the next one I said above, and this editor is not the same as ordinary, there is insertion mode, command mode, etc. need to check how to operate, here simply say into the editor after pressing the i key into insertion mode, and then on the normal editing file, after the completion of esc exit insert mode, direct input: wq command is to save and exit

Restart the service

service ssh restart

At this point, you can connect remotely, open a cmd window through the ssh-p port number username@IP address, or any other tool can be successfully connected to enter the ubuntu environment, then you can use the linux command.

Recommended lessons: Docker Basic Getting Started, Docker from Getting Started to Practice