1、创建网络

docker network create -d bridge mynetwork

2、配置  docker-compose.yml的network

docker-compose1.yml

  1. version: "3"

  2. services:

  3. redis:

  4. image: redis:5.0.3

  5. container_name: redis

  6. networks:

  7. - default

  8. - mynetwork

  9. mysql:

  10. image: mysql:5.7

  11. container_name: mysql

  12. networks:

  13. - default

  14. - mynetwork

  15. networks:

  16. mynetwork:

  17. external: true


docker-compose2.yml

  1. version: "3"

  2. services:

  3. php:

  4. image: php:7.1

  5. container_name: php

  6. networks:

  7. - default

  8. - mynetwork

  9. external_links:

  10. - redis

  11. - mysql

  12. networks:

  13. mynetwork:

  14. external: true

作者 灰武士