How to install docker on Linux system and log in to docker container through ssh

How to install docker on Linux system and log in to docker container through ssh

Note: I use Centos to install docker

Step 1: Install Docker

sudo yum install -y yum-utils 

sudo yum-config-manager --add-repo https://download.daocloud.io/docker/linux/centos/docker-ce.repo 

sudo yum install -y -q --setopt=obsoletes=0 docker-ce-17.09.1.ce* docker-ce-selinux-17.09.1.ce* 

sudo systemctl enable docker 
sudo systemctl start docker 
sudo service docker status 

Note: This is what I installed before, so the system does not need to update most things.

If you want to install other versions of docker under Linux, you can go to this website to see the installation command:

https://download.daocloud.io/Docker_Mirror/Docker Click to open the link

Step 2: Configure Docker Accelerator

Register an account on DaoCloud (www.daocloud.io), scroll down to the end and click Accelerator

Copy this configuration accelerator code and run

Step 3: Install Ubuntu system on Docker

docker search ubuntu to see which versions of ubuntu images are available

docker search ubuntu

I use docker pull ubuntu to download the first one directly:

docker images View the downloaded docker image:

docker run -tid --name ubuntu -p 23:22 ubuntu: Name the newly created docker as ubuntu and map it to port 23

netstat -apnl | grep 23 Check whether port 23 is open

You can see that port 23 is open.

docker exec -ti ubuntu /bin/bash to enter Ubuntu of docker (or use dockerrun -i -t ubuntu /bin/bash), and then change the root password through the passwd command.

Step 4: Log in to the docker container using ssh

apt install -y vim install (update) vim

Because unable to locate package appears, you need to update the source.

Then install openssh-server: apt install -y openssh-server

After successful installation, vim /etc/ssh/sshd_config, modify the following configuration so that you can log in directly as root:

1) Add PermitRootLogin yes

I commented out the above sentence and added PermitRootLogin yes.

2) Add UsePAM no

Start the ssh service, service sshstart

Exit docker, enter docker ps -a to view the docker ID

Open a new terminal and enter docker via ssh [email protected] -p 23:

Or you can directly configure a new session in xshell, add the port number (23) we set previously, and log in.

Reminder: The server I use is from Alibaba Cloud. Many ports of Alibaba Cloud are not open by default. The port 23 I set is not open either. Please note that you need to go to the Alibaba Cloud console to open it, otherwise you will not be able to ssh in.

Step 5: We can also store this ubuntu image:

Use sudo docker save -o ubuntu.zip ubuntu will be stored in the current directory.

Then load the image on any machine:

Step 6: If we don’t like the existing image, we can also delete it:

View the ID of the installation container

Shut down the docker container before deleting:

Then delete: docker rm + installation container ID

You can see that no container is working, so you can't log in now.

At this point, the Linux system has installed Docker and configured to log in to the Docker container using ssh.

The above article about how to install docker on Linux system and log in to docker container with ssh is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Pytorch converts to TensorRT5 by saving as ONNX model
  • How to install and uninstall docker application container engine under Centos7
  • Summary of common Docker commands: installation, mirroring, and basic container operations
  • Specific steps to install ssh in the docker container
  • Problems installing TensorRT in docker container

<<:  Summary of MySQL view principles and usage examples

>>:  JavaScript adds prototype method implementation for built-in objects

Recommend

Implementation of CSS text shadow gradually blurring effect

text-shadow Add a shadow to the text. You can add...

Summary of 6 solutions for implementing singleton mode in JS

Preface Today, I was reviewing the creational pat...

Nginx monitoring issues under Linux

nginx installation Ensure that the virtual machin...

How to start the spring-boot project using the built-in linux system in win10

1. Install the built-in Linux subsystem of win10 ...

Solution to ONLY_FULL_GROUP_BY error in Mysql5.7 and above

Recently, during the development process, the MyS...

Using Nginx to implement grayscale release

Grayscale release refers to a release method that...

Detailed explanation of several ways to create objects and object methods in js

This article is the second article about objects ...

User experience analysis of facebook dating website design

<br />Related article: Analysis of Facebook&...

Detailed explanation of CSS3 text shadow text-shadow property

Text shadow text-shadow property effects: 1. Lowe...

Why MySQL does not recommend using null columns with default values

The answer you often hear is that using a NULL va...

Ajax responseText parses json data case study

Solve the problem that the responseText returned ...