I have just started learning docker . This is my docker-compose.yml file . It shows the following error "services.catalog.api.networks must be a list" When I docker compose up
version: '3.4'
networks:
testnetwork:
driver: bridge
services:
orderdb:
image: mongo
catalogdb:
image: mongo
orderapi:
image: orderapi
build:
context: .
dockerfile: OrderApi/Dockerfile
ports:
- 5243:5243
networks:
testnetwork
catalog.api:
image: farhanpatel/catalogapi
build:
context: .
environment:
- ASPNETCORE_ENVIRONMENT=Development
- "DatabaseSettings:ConnectionString=mongodb://catalogdb:27017"
depends_on:
- catalogdb
ports:
- "5116:5116"
networks:
testnetwork
volumes:
mongo_data:
I want to connect both orderapi and catalogapi through docker bridge network.
I have created a bridge network named testnetwork and used it in above docker-compose.yml .
Could someone explain how should I connect both the images
2
Answers
You should separate app form Mongodb. My example docker-compose(node.js,MongoDB)
command
to list networks
And to inspect
will give you
You should also read some Docker books or courses where you have step by step explained.
You should just delete all of the
networks:
blocks in the entire file. Compose on its own creates a network nameddefault
and attaches containers to it, and this is enough for all standard Docker networking functionality to work. Also see Networking in Compose in the Docker documentation.If you do have
networks:
, a container can be attached to multiple networks, and so the value of the per-containernetworks:
needs to be a YAML list. Usually this means putting-
at the front of the line (the space is important). You need to do this for all of your containers; in the example as you’ve shown it, the API servers would be ontestnetwork
but the databases still on thedefault
network.