since 2 weeks or so I have an issue with docker compose while changing anything on my compose files (or at least i do not remember).
When docker compose up is run, sometimes (rarely) a container does not get added to one or multiple of the networks defined in the yml file. For example, I have some backend containers, that are all connected to a database container using a network. However, sometimes one of the backend containers ends up without a connection to the DB. When analyzing with docker network inspect I found out that the relevant backend container did not "join" the network.
I made sure that the db container is up before the backend containers are started, however if this was the problem, i think there should have been an error message anyways, since the db compose file defines the network, which is external in the backend compose file.
DB compose file:
version: "3.5"
services:
db:
restart: always
image: postgres:15.2-alpine
volumes:
- postgres_data:/var/lib/postgresql/data
- ./postgres.conf:/etc/postgresql/postgresql.conf:ro
environment:
- POSTGRES_PASSWORD=${DB_MASTER_PWD}
command: postgres -c config_file=/etc/postgresql/postgresql.conf -c logging_collector=on -c log_directory=/logs/postgresql -c log_filename=postgresql.log -c log_statement=ddl
ports:
- 127.0.0.1:5432:5432
networks:
- db
container_name: postgres
volumes:
postgres_data:
networks:
db:
Backend(1) compose file:
version: "3.5"
services:
backend_1:
restart: always
build:
context: ${DOCKER_FILES_PATH}/customer-compose/backend/
dockerfile: Dockerfile
args:
...
image: ${BE_IMAGE_NAME}
volumes:
...
networks:
- postgres_db
environment:
...
container_name: backend_1
networks:
postgres_db:
external: true
docker-compose
suddenly wanted our networks to become external docs.docker.com/compose/compose-file/06-networks/#external and now the documentation become true here: We have to create our networks manually and compose itself does not create them anymore. I wanted to proof this via the changelogs of docker but I did't find a real answer here too