Reputation: 7623
When I try to docker-compose my docker-compose.yml file with "network_mode", I receive the following error:
ERROR: The Compose file './docker-compose.yml' is invalid because: services.combined.network_mode contains an invalid type, it should be a string
My docker-compose.yml file:
version: '3'
services:
dbrs:
hostname: localhost
build:
context: .
dockerfile: ./docker/dbrs/Dockerfile
volumes:
- dbdata:/data/db
ports:
- "27017:27017"
- "27018:27018"
- "27019:27019"
networks:
- app-network
combined:
build:
context: .
dockerfile: ./docker/combined/Dockerfile
env_file: .env
ipc: host
volumes:
- .:/home/node/app
- ./cypress:/usr/src/app/cypress
- node_modules:/home/node/app/node_modules
- /tmp/.X11-unix:/tmp/.X11-unix
- /dev/shm:/dev/shm
ports:
- "5000:5000"
- "8080:8080"
networks:
- app-network
network_mode:
- "service:dbrs"
depends_on:
- dbrs
networks:
app-network:
driver: bridge
volumes:
dbdata:
node_modules:
As far as I'm aware, network_mode should be available for version 3 per the docs. My docker-compose version is 1.24.1, build 4667896.
Is there any other reason why I can't use "network_mode" in my docker-compose.yml file?
Upvotes: 0
Views: 5184
Reputation: 158847
When you say:
network_mode:
- "service:dbrs"
The new line, hyphen declares a YAML list. As the error message notes, this needs to be a single string and not a list; the value should be on the same line.
network_mode: "service:dbrs"
(It's pretty unusual to directly connect to another service's network stack like this. If you need to communicate with the other container, you can use its Compose service name and internal port number, dbrs:27017
. Networking in Compose has more details.)
Upvotes: 3