docker-composeCannot link to as it does not belong to the default network
This error message occurs when you try to use the links option in your Docker Compose file to link two containers that are not on the same network. By default, Docker Compose creates a network for your containers to communicate with each other, but if you try to link a container that is not on this network, you will get this error message.
To fix this error, you can either add the container to the default network by specifying the network in your Docker Compose file or create a custom network for both containers to join.
Here's an example of adding a container to the default network:
version: '3'
services:
app:
image: myapp
networks:
- default
db:
image: mysql
networks:
- default
And here's an example of creating a custom network:
version: '3'
services:
app:
image: myapp
networks:
- mynetwork
db:
image: mysql
networks:
- mynetwork
networks:
mynetwork:
driver: bridge
In both cases, the containers will be able to communicate with each other via the specified network
原文地址: https://www.cveoy.top/t/topic/eSK8 著作权归作者所有。请勿转载和采集!