我有 2 个 docker-compose 文件
1:
version: "3.1"
services:
database:
image: mysql:5.6
networks:
mynetwork:
driver: bridge
2:
version: "3.1"
services:
api:
image: myapi:1
networks:
mynetwork:
external: true
但在 api
容器内,找不到主机名 database
。我也试过 mynetwork_database
但也没有找到
如何访问外部网络上的容器?
答案 0 :(得分:0)
解决方案是添加:
networks:
<mysql_project_folder_name>_mynetwork:
external: true
还有:
networks:
- <mysql_project_folder_name>_mynetwork
到api
服务