記錄下(同一個計算機)多個容器 dockr bridge(橋接) docker-compose 配置

首先先配置好橋接容器(mysql_bridge 爲一個橋接網絡,A容器能夠在此暴露A容器的服務接口,讓B容器使用A容器的服務)mysql

docker network mysql_bridge

 

直接上web

version: '3'

services:
  mysql:
    container_name: mysql
    image: mysql:5.7.21
    environment:
      MYSQL_ROOT_PASSWORD: root
    volumes:
      - ./data/mysql:/var/lib/mysql
    expose:
      - 3306
    ports:
      - 3306:3306
    networks:
      - mysql_bridge
    restart: on-failure

  redis:
    container_name: redis
    image: redis:4.0.6
    expose:
      - 6379
    ports:
      - 6379:6379
    volumes:
      - ./data/redis:/usr/share/redis/data:rw
    networks:
      - redis_bridge

  mongo:
    container_name: mongo
    image: mongo:4.0.9
    volumes:
      - ./data/mongo:/data/db
    expose:
      - 27017
    ports:
      - 27017:27017
    networks:
      - mongo_bridge
    restart: on-failure

networks:
  mysql_bridge:
    external: true
  redis_bridge:
    external: true
  mongo_bridge:
    external: true

 容器使用橋接例子:redis

version: '3'

services:
  web:
    container_name: web
    build:
      context: ./
    volumes:
      - ./:/var/www
    ports:
      - 81:80
    external_links:
        - mysql
        - redis
    restart: on-failure
    networks:
      - mysql_bridge
      - redis_bridge


networks:
  mysql_bridge:
    external: true
  redis_bridge:
    external: true
相關文章
相關標籤/搜索