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

Detailed explanation of Nginx version smooth upgrade solution

Table of contents background: Nginx smooth upgrad...

Example of using Docker Swarm to build a distributed crawler cluster

During the crawler development process, you must ...

Native js to achieve accordion effect

In actual web page development, accordions also a...

Install Kafka in Linux

Table of contents 1.1 Java environment as a prere...

How to limit the number of concurrent connection requests in nginx

Introduction The module that limits the number of...

JS uses map to integrate double arrays

Table of contents Preface Simulating data Merged ...

Centos 7 64-bit desktop version installation graphic tutorial

If you think the system is slow and want to chang...

Detailed steps for running springboot project in Linux Docker

Introduction: The configuration of Docker running...

10 skills that make front-end developers worth millions

The skills that front-end developers need to mast...

MySQL string splitting operation (string interception containing separators)

String extraction without delimiters Question Req...