Reputation: 97
I have a question regarding using the network_host mode. I have a 3 to 4 spring-boot services in a docker_compose which I want to communicate with each other. Initially, I was using a custom network for interconnectivity of the services for this I had to specify the host url with each port, but then I found the network_mode host which I think is more easy for me with less code change. My question is what is the best practice to have a custom network? Or we can use the network_mode host for services to communicate with each other?
Below is my docker-compose file.
version: '3'
services:
redis:
image: redis
ports:
- "6379:6379"
cas-service:
container_name: cas-service
image: localhost:5000/cas-service:docker-1.0
volumes:
-/DiGiID:/DiGiID
ports:
- "8082:8082"
depends_on:
- redis
eureka-service:
container_name: eureka-service
image: localhost:5000/eureka-service:docker-1.0
volumes:
-/DiGiID:/DiGiID
ports:
- "8301:8301"
user-service:
container_name: user-service
image: localhost:5000/user-service:docker-1.0
volumes:
-/DiGiID:/DiGiID
ports:
- "8302:8302"
depends_on:
- cas-service
sftp-service:
container_name: sftp-service
image: localhost:5000/sftp-service:docker-1.0
volumes:
-/DiGiID:/DiGiID
ports:
- "8333:8333"
depends_on:
- cas-service
product-service:
container_name: product-service
image: localhost:5000/product-service:docker-1.0
volumes:
-/DiGiID:/DiGiID
ports:
- "8304:8304"
depends_on:
- cas-service
device-service:
container_name: device-service
image: localhost:5000/device-service:docker-1.0
volumes:
-/DiGiID:/DiGiID
ports:
- "8303:8303"
depends_on:
- cas-service
digiid-service:
container_name: digiid-service
image: localhost:5000/digiid-service:docker-1.0
volumes:
-/DiGiID:/DiGiID
ports:
- "8080:8080"
Upvotes: 1
Views: 656
Reputation: 992
You scenario looks good for bridge network mode. If you use host network mode, it will take host properties and then you need to isolate your host machine to eradicate any kind of security threats.
Upvotes: 0
Reputation: 10727
If your services are all declared in the same docker-compose.yml file then you should connect them directly (service name and internal port), not through the ports mapped on the host. If they are defined in different files then you can still put them on the same network and connect them by service name and internal port.
If you port your docker-compose.yml I can explain better for your situation.
In general, avoid using the host network unless you have no other choice.
Upvotes: 1