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
You need to add "gt_" in front of the f...
Table of contents Ref and Reactive Ref Reactive T...
Preface When sharing a page, you hope to click th...
This article attempts to write a demo to simulate...
Preface I always thought that UTF-8 was a univers...
Seurat is a heavyweight R package for single-cell...
There are various environmental and configuration...
Table of contents 1. Problem Background 2. What a...
This article describes how to install MySQL 5.7 f...
When the jsp that is jumped to after the struts2 a...
Linux has been loved by more and more users. Why ...
1 Question The company's server uses Apache, ...
1. Problem The docker container logs caused the h...
Preface We all know that in Linux, "everythi...
1. First, use springboot to build a simple dubbo ...