I have the following docker-compose.yml file:
version: "3.9"
services:
result:
image: result
ports:
- "8080:80"
networks:
- test-wp-network
And network:
docker network list | grep test
a18a8c7a2764 test-wp-network bridge local
But when I run docker-compose up the following error is shown:
service "db" refers to undefined network test-wp-network: invalid compose project
Could you please clarify what is the issue and how it can be fixed?
For example, if I run it as below:
docker run --name=db -e POSTGRES_PASSWORD=mysecretpassword --network=test-wp-network postgres:9.4
It is workin fine
3
Answers
Try with this compose file change image and tag
you need to declare networks before you use it in services.
see Specify custom networks and Use a pre-existing network from
docker
manuals.here is a sample config
As you do have the network exist, Docker-compose will create a new network for any application you ran. beside what you already have.
This network will be accessible for all the services inside your application, and not accessible for other services inside other docker applications.
In case you need to share the access for this network, you have to define external network, usually at the end of the
docker-compose.yaml
like the following :