How to connect to docker server using ssh

How to connect to docker server using ssh

When I first came into contact with docker, I was really confused. I read the novice tutorial for a long time but still couldn't use it. Now at least I understand that docker is a container that can hold various software. If you put Ubuntu in it, this container can be regarded as Ubuntu used in other environments.

download

Just follow the tutorial, there is nothing much to say, here is the installation tutorial in Novice

https://www.runoob.com/docker/windows-docker-install.html

Mainly talk about how to create a docker service so that others can connect and use it through ssh (taking ubuntu as an example) Create a container

You need an image. Friends who have used Ubuntu and other image installations should understand this. If you don’t have one, you can download one by using docker pull 鏡像名.

Create a container in the ubuntu image and map port 50003 of the docker server to port 22 of the container

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

At this time, we can see that our container has started using docker ps

insert image description here

Enter the container by ID

docker exec -it a9cbce70127f /bin/bash

At this point we have entered the container, that is, in the Ubuntu environment

insert image description here

Install SSH Server

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

When you install the ssh service here, you will be asked to select the time zone. Just use the number to select it. I use 6 31

Tips: If you use the command and report that the command cannot be found, you can directly use apt-get install 命令名to install this command

Set the root password through the passwd command

insert image description here

Start ssh service

service ssh start

You can use ps -e |grep ssh to check whether the service is started.

Modify the configuration file

Open the configuration file using the vim editor

vim /etc/ssh/sshd_config

Write the following content in the configuration file (the # sign is a comment)

PubkeyAuthentication yes # Enable public key and private key pairing authentication method AuthorizedKeysFile .ssh/authorized_keys # Public key file path PermitRootLogin yes # Root can use ssh to log in

If there is no vim command here, just press the next one I mentioned above. In addition, this editor is different from the ordinary one. There are insert mode, command mode, etc. You need to check how to operate it specifically. Here is a brief introduction. After entering the editor, press i key to enter the insert mode, and then edit the file normally. After completion, press esc to exit the insert mode. Directly enter :wq command is to save and exit

Restart the service

service ssh restart

At this time, you can connect remotely. Open a cmd window and use ssh –p端口號用戶名@IP地址or other tools to connect successfully to enter the Ubuntu environment. Then you can use Linux commands.

This is the end of this article about how to use ssh to connect to the docker server. For more information about how to use ssh to connect to the docker server, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed tutorial of pycharm and ssh remote access server docker
  • How to install docker on Linux system and log in to docker container through ssh
  • How to create a Docker image that supports SSH service
  • Specific steps to install ssh in the docker container
  • Specific steps to install ssh in docker centos7
  • Docker uses Dockerfile to create a container image that supports automatic startup of ssh service

<<:  HTML Tutorial: Collection of commonly used HTML tags (6)

>>:  Vue implements image dragging and sorting

Recommend

Example code for implementing 3D Rubik's Cube with CSS

Let's make a simple 3D Rubik's Cube today...

Detailed explanation of incompatible changes in rendering functions in Vue3

Table of contents Rendering API changes Render fu...

Example of using MySQL to count the number of different values ​​in a column

Preface The requirement implemented in this artic...

A screenshot demo based on canvas in html

Written at the beginning I remember seeing a shar...

WeChat applet implements countdown for sending SMS verification code

This article shares the specific code for the WeC...

How to use domestic image warehouse for Docker

1. Problem description Due to some reasons, the d...

Web Design Help: Web Font Size Data Reference

<br />The content is reproduced from the Int...

Node and Python two-way communication implementation code

Table of contents Process Communication Bidirecti...

Nginx service 500: Internal Server Error one of the reasons

500 (Internal Server Error) The server encountere...

Detailed explanation of CSS BEM writing standards

BEM is a component-based approach to web developm...

nginx automatically generates configuration files in docker container

When a company builds Docker automated deployment...

Analysis of the solution to Nginx Session sharing problem

This article mainly introduces the solution to th...

Example code for element multiple tables to achieve synchronous scrolling

Element UI implements multiple tables scrolling a...

Detailed explanation of HTML table inline format

Inline format <colgroup>...</colgroup>...