Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to remotely connect containers in docker through ssh

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to connect containers in docker remotely through ssh". In daily operation, I believe many people have doubts about how to connect containers in docker remotely through ssh. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to remotely connect containers in docker through ssh". Next, please follow the editor to study!

Demand:

I want to build a lnmp environment for ubuntu myself, but when using powershell, there are all kinds of awkwardness, so consider remote connection, through putty or xshell to connect

Environment:

System: Win10

Docker:Version 17.06.0-ce-win19 (12801)

Container Management: kitematic for windows

Remote connection tool: xshell

Container system: ubuntu

Process:

Download the ubuntu container

Download the latest official version of ubuntu from ketematic

Remarks: 1. Aliyun or other domestic images are recommended, which are very fast.

2. If you don't use ubuntu, you can also use other linux distributions, all of which are similar

II. Preparatory work

Because many commands are not available in the newly installed official ubuntu, you need to install it yourself.

Apt-get update

Apt-get install vim

Initialize the password for root

Sudo passwd root (use passwd root if the sudo command does not exist)

Then set the password. For example, the password I set directly is root.

Remarks: 1. If you do not want to use root account, you can add other accounts, configure ssh and use other accounts when logging in.

Third, install ssh

Installation

Apt-get install openssh-server

View statu

Service ssh status

Turn on ssh

Service ssh start

Configure ssh and run root login

Vim / etc/ssh/sshd_config

The value of PermitRootLogin changed from prohibit-password to yes

As follows:

-PermitRootLogin prohibit-password + PermitRootLogin yes

Save after editing, and then restart ssh

Service ssh restart

Save changes to the current container

Open through kitematic, or open docker command operation through Docker Quickstart Terminal

Docker ps to see which docker is currently running

You can see what the container ID of the currently running ubuntu is.

Save the new container

Docker commit 66b34b5228d8

Remarks: 1. Syntax is docker commit container ID

Configure the container with an accessible port

Since the port of ssh is 22, we configure an external port to access the port in the container

Once configured, click Save, and the container will restart automatically.

Remarks: 1. The external port can be easily configured with a non-conflicting port. The 50001 I configured here

2. After restarting the container, you may need to restart ssh,service ssh start

Connect the container through xshell and putty

All the above work is done, and we need to access it through the ip address of the docker (not through the ip address of the container, because it needs to be mapped).

Local cmd- "ipconfig to view the ip address of the current docker

Then the address that we ssh accesses is 192.168.56.1 virtual 50001 configured in the above two steps.

The account is root and the password is root

You can connect through ssh client tools such as putty or xshell

At this point, the connection is successful

At this point, the study on "how to remotely connect containers in docker through ssh" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report