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

The method of interconnecting docker compose containers

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the docker compose container interconnection method related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will get something after reading this docker compose container interconnection method article, let's take a look at it.

Haproxy connects to nginx container

# # write mkdir / mnt/composevim docker-compose.ymlweb1: image: nginx expose:-80 volumes: -. / web1:/usr/share/nginx/htmlweb2: image: nginx expose:-80 volumes: -. / web2:/usr/share/nginx/ for compose of the service Htmlhaproxy: image: haproxy volumes: -. / haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro links:-web1-web2 ports:-"80:80" expose:-80##haproxy configuration file [root@server1 compose ] # mkdir web1 [root@server1 compose] # mkdir web2 [root@server1 compose] # echo web1 > web1/index.html [root@server1 compose] # echo web2 > web2/index.html [root@server1 compose] # mkdir haproxy [root@server1 compose] # lsdocker-compose.yml haproxy web1 web2 [root@server1 compose] # vim haproxy/haproxy.cfg [root@server1 compose] # cat haproxy/haproxy.cfg global log 127.0.0.1 local0 log 127.0.0.1 local1 noticedefaults log global mode Http option httplog option dontlognull timeout connect 5000ms timeout client 5000ms timeout server 5000ms stats uri / statusfrontend balancer bind 0.0.0.0:80 default backend web_backendsbackend web backends balance roundrobin server server1 web1:80 check server server2 web2:80 check

The key point is how to configure how containers are connected to each other.

1, first specify the service name in the compose file. Then configure links

2, specify the name of the service in the configuration file

Some knowledge of docker-compose configuration file #

Network_mode: set network mode network_mode: "bridge" network_mode: "host" network_mode: "none" network_mode: "service: [service name]" network_mode: "container: [container name/id]" links: connect the specified container to the current connection. You can set an alias. Avoid container restart caused by ip cannot be connected dynamically links: # specify service name: alias-docker-compose-eureka-server:compose-eureka update container: when the configuration of the service changes, you can use the docker-compose up command to update the configuration. At this time, Compose will delete the old container and create a new container. The new container will join the network with a different IP address, and the name will remain the same. Any connection to the old container will be closed, and the new container can be found again and connected to the links service. Links services can access each other using service names, and links allows you to define an alias to access other services version: '2'services: web: build:. Links:-"db:database" db: image: postgres this article on "how to interconnect docker compose containers" ends here. Thank you for reading! I believe you all have some knowledge about "the method of interconnecting docker compose containers". If you want to learn more, you are welcome to follow the industry information channel.

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

Development

Wechat

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

12
Report