I’m trying to define my networks in separate docker-compose.yml file (docker-compose.networks.yml
).
Here it is:
version: '3.8'
networks:
pypinfo-rabbitmq:
name: pypinfo_rabbitmq
driver: bridge
When I try to apply this configuration it shows the following warning:
WARNING: Some networks were defined but are not used by any service: pypinfo-rabbitmq
The main configuration file is:
version: '3.8'
services:
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: pypinfo_rabbitmq
ports:
- "5672:5672"
- "15672:15672"
environment:
- RABBITMQ_DEFAULT_USER
- RABBITMQ_DEFAULT_PASS
- RABBITMQ_DEFAULT_VHOST
volumes:
- rabbitmq_data:/var/lib/rabbitmq/
- rabbitmq_log:/var/log/rabbitmq/
networks:
- pypinfo-rabbitmq
volumes:
rabbitmq_data:
driver: local
rabbitmq_log:
driver: local
networks:
pypinfo-rabbitmq:
external:
name: pypinfo_rabbitmq
And when I apply my main configuration file for my services it says:
ERROR: Network pypinfo_rabbitmq declared as external, but could not be found. Please create the network manually using `docker network create pypinfo_rabbitmq` and try again.
The question: Why are my networks defined in docker-compose.networks.yml
not created? Why should I do to force docker-compose
to create them?
2
Answers
I found a solution. I can just apply both files at the same time:
It will create the network and containter that has this network in
networks
section in configuration:Try to create network before running docker compose up