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

Create a movable stack widget function using flutter

This post focuses on a super secret Flutter proje...

The concept of MySQL tablespace fragmentation and solutions to related problems

Table of contents background What is tablespace f...

Modularity in Node.js, npm package manager explained

Table of contents The basic concept of modularity...

Vue uses better-scroll to achieve horizontal scrolling method example

1. Implementation principle of scrolling The scro...

How to analyze MySQL query performance

Table of contents Slow query basics: optimizing d...

How to solve the Docker container startup failure

Question: After the computer restarts, the mysql ...

html+css+js to realize the function of photo preview and upload picture

Preface: When we are making web pages, we often n...

How to install MySQL 5.7 from source code in CentOS 7 environment

This article describes how to install MySQL 5.7 f...

Solution to IDEA not being able to connect to MySQL port number occupation

I can log in to MYSQL normally under the command ...

Our thoughts on the UI engineer career

I have been depressed for a long time, why? Some t...

MySQL full backup and quick recovery methods

A simple MySQL full backup script that backs up t...

How to set the style of ordered and unordered list items in CSS

In an unordered list ul>li, the symbol of an u...

Interpretation of syslogd and syslog.conf files under Linux

1: Introduction to syslog.conf For different type...

Solve the problem of the container showing Exited (0) after docker run

I made a Dockerfile for openresty on centos7 and ...