Today I experimented with the network settings under Docker and recorded the process so as not to forget it later. (System: Centos 7.4, docker version: 18.03.1-ce, docker-compose version 1.18.0) cat docker-compose.yml version: '3' services: test1: image: busybox:latest # The image is busybox entrypoint: #Execute the top command after the container is started so that the container cannot exit immediately - top networks: backend: # Use the specified network backend and set the network alias to test1. aliases: # After setting the network alias, you can ping test1 in other containers to access the container - test1 test2: image: busybox:latest entrypoint: - top networks: backend: aliases: -test2 networks: backend: start up docker-compose up -d docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4d05ceb2088d busybox:latest "top" 5 seconds ago Up 4 seconds ibaboss_test2_1 f4ccafa24664 busybox:latest "top" 5 seconds ago Up 4 seconds ibaboss_test1_1 docker exec -it 4d05ceb2088d /bin/sh /# ping test1 PING test1 (172.19.0.2): 56 data bytes 64 bytes from 172.19.0.2: seq=0 ttl=64 time=0.061 ms 64 bytes from 172.19.0.2: seq=1 ttl=64 time=0.062 ms ping ibaboss_test1_1 PING ibaboss_test1_1 (172.19.0.2): 56 data bytes 64 bytes from 172.19.0.2: seq=0 ttl=64 time=0.045 ms 64 bytes from 172.19.0.2: seq=1 ttl=64 time=0.056 ms 64 bytes from 172.19.0.2: seq=2 ttl=64 time=0.061 ms # In the network, you can communicate through the container name or the network alias The format of the Compose container name is: <project name><service name><serial number> Although you can customize the project name and service name, if you want to have full control over the naming of the container, you can use this tag to specify it: container_name: app cat docker-compose_v1.yml version: '3' services: test1: image: busybox:latest entrypoint: - top container_name: test1 networks: - backend test2: image: busybox:latest entrypoint: - top container_name: test2 networks: - backend networks: backend: start up docker-compose -f docker-compose_v1.yml up -d docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 132859fc77c2 busybox:latest "top" About a minute ago Up About a minute test2 cd0a78dc9bd4 busybox:latest "top" About a minute ago Up About a minute test1 docker exec -it 132859fc77c2 ping test1 PING test1 (172.19.0.2): 56 data bytes 64 bytes from 172.19.0.2: seq=0 ttl=64 time=0.070 ms 64 bytes from 172.19.0.2: seq=1 ttl=64 time=0.068 ms 64 bytes from 172.19.0.2: seq=2 ttl=64 time=0.059 ms Replenish: Docker compose multi-container shared network problem A few days ago, I planned to use docker compose to write multiple containers to share a container network, but I always got an error. Today I tried it again and found that it was caused by the port binding problem. The port can only be bound to the container that generates the network card. If it is bound to other windows, an error will be reported. In the following code, the mysql service shares the nginx network card. When port:3306 is used in mysql, it will fail to run. Move 3306 to nginx and start it successfully. version: '3.3' services: nginx: image: "lnp_php" # container_name: "lnmp_nginx" ports: - "80:80" - "443:443" - "3306:3306" expose: - "3306" volumes: - /home/www/php:/home/www:rw # depends_on: # -mysql # links: # -mysql mysql: image: "mysql" # container_name: "lnmp_mysql" # ports: # - "3306:3306" # expose: # - "3306" volumes: - /home/docker/conf/mysql_w:/etc/mysql:rw environment: -MYSQL_ROOT_PASSWORD=123456 depends_on: - nginx network_mode: "service:nginx" The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Bootstrap FileInput implements image upload function
>>: Summary of MySQL injection bypass filtering techniques
When there are tens of thousands of records in th...
Html semantics seems to be a commonplace issue. G...
Copy code The code is as follows: <form action...
Preface The service has been deployed on MySQL fo...
1. Use curl command to access by default: # curl ...
CSS sets Overflow to hide the scroll bar while al...
Introduction Memcached is a distributed caching s...
Table of contents 1. Bootstrap Grid Layout 2. Ver...
Preface Students who learn JavaScript know that A...
On CentOS 7, when we map the host port to the con...
View Database show databases; Create a database c...
1. Introduction to Distributed Storage System Wit...
This article uses examples to describe MySQL tran...
Arrange by functionNN : Indicates which earlier ve...
Table of contents Implementing a search engine ba...