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 connect containers in docker

2025-01-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article will explain in detail how to connect containers in docker. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Docker official sources mentioned starting a parent container with a training/postgre image, but for some reason, the container stopped itself. I'll just commit a new container.

Here is a supplement to the practice of commit containers:

Start the container from image:

Docker run-t-I training/webapp / bin/bash

As a test, I didn't make any changes and went straight back to the host commit:

Root@046a0ea81e8a:/opt/webapp# exitexit

Commit container:

Docker commit-m = "Nothing to do"-a = "Hochikong" 046a0ea81e8a newimage/webapp:v1

In short, you remember the ID of the previous container, which will be used in commit. -m serves as a supplement to commit,-a specifies the author, followed by newimage/webapp is the new image name, and v1 is tag.

The results are as follows:

Root@workgroup:~# docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEnewimage/webapp v1 7ef236b535c8 4 seconds ago 278.8 MBwebapp/ntpplus v1 18d60ce37ee5 41 hours ago 316.9 MBhochikong/erbuntu v1 e3095ca4cf38 13 days ago 368.3 MBdbehnke / ubuntu1404 latest 31c0939ea86c 5 weeks ago 368.3 MBtraining/postgres latest 258105bea10d 11 weeks ago 364.6 MBtraining/webapp latest 31fa814ba25a 12 weeks ago 278.8 MB

Back to the point:

Let's first create a basic container (parent container):

Use-- name to name the container (each container must have a unique, non-repeatable name) as base

Run another container, named web, and use-- link to connect to base. Wbconc is the name of this connection, and to prevent port conflicts, I use-p to bind port 1000 of the host to port 5000 of the container:

I also ran a (play) named web2 and the connection name was wbconc2:

Check my container status:

You can see that in the NAME column of the container base, there are two more items, web/wbconc and web2/wbconc2, before the "/" is the name of the child container (that is, web and web2), followed by the name of the connection (wbconc and webconc2), and their parent container is base.

In this translation, ‍‍‍ http://www.widuu.com/chinese_docker/userguide/dockerlinks.html

There are several errors and differences. I use nsenter to connect to the container, but I don't see that the container's hosts file has been modified as described in the original. The problem arises.

I first get the Pid of three containers (I can't parse JSON, just use grep):

Use nsenter to enter the base container (please refer to my previous blog post about installing nsenter):

You can see the IP address of the container. Although ping can ping other containers, you cannot set hosts for them. The egg hurts. Is there anyone who can solve this problem? if not, do you need DNS? It's too much trouble!

The hosts file has nothing mentioned in the original text at all. I don't know where it came from, hosts.

This is the end of the article on "how to connect containers in docker". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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: 298

*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