But when I make a GET request on B, I got an error :
GET http://localhost:8000 dial tcp 127.0.0.1:8000 refused
How can I fix that?
docker-compose ps just tells me the port which is 8000/tcp
Can you show us your docker-compose.yml file? The name used for the link between two containers actually creates an alias to connect to, just like localhost is an alias for 127.0.0.1: https://docs.docker.com/compose/yml/#links
So you shouldn't be connecting via localhost in your GET request. Instead, use the name that is used in the link to service B, with the port after it. Here is an example config file with the appropriate GET request url:
docker-compose.yml:
service_a:
image: service_a_image
ports:
- 7000 # maps port to host
links:
- service_b
service_b:
image: serivce_b_image
expose:
- 8000 # exposes port to other containers
Get URL from service A to B:
http://service_b:8000
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With