[Docker] 两份docker-compose.xml共用一个network

1. 先起neo4j数据库和一个网络:

version: '3'
services:

  neo4j:
    image: neo4j:3.5.5
    volumes:
      - ./conf:/var/lib/neo4j/conf
      - ./mnt:/var/lib/neo4j/import
      - ./plugins:/plugins
      - ./data:/data
      - ./logs:/var/lib/neo4j/logs
    restart: always
    ports:
      - 7474:7474
      - 7687:7687
    environment:
      - NEO4J_dbms_memory_heap_maxSize=4G
      - NEO4J_AUTH=neo4j/123456
    networks:
      - my-network

networks:
    my-network:
      driver: bridge

2. 随后起的服务需要加入原先的网络:

先查看下之前起的网络实际叫什么名字:

[root@CENTOS-MASTER cutter]# docker network ls
NETWORK ID          NAME                          DRIVER              SCOPE
1918b6df97b5        bridge                        bridge              local
cd415863acc5        docker-neo4j_my-network   	bridge              local
ee4b01a94aad        host                          host                local
0f77a2b4f416        none                          null                local

可以看到原来的网络实际名字前面要加上原项目目录的名字,所以第二个docker-compose文件如下:

version: '3'
services:

  [service2-name]:
    build: .
    image: [service2-image-name]
    restart: always
    networks:
      - docker-neo4j_my-network
	...

networks:
  docker-neo4j_my-network:
    external: true

你可能感兴趣的:(微服务)