Assuming you have docker
and docker-compose
set up, run docker-compose up -d
.
A docker image should be treated as a completely separate machine, so a call to localhost:5000
on your machine is not the same as a call to localhost:5000
in your container.
Your two options to contact other services over localhost are:
- Don't do that, and use the service's alias instead. For example, a call to
localhost:5000
becomesserver:5000
when you service is namedserver
. This works becausedocker-compose
creates a default network over which your containers can communicate. - Specify the
network_mode
ashost
for the client container. Ahost
network mode will make sure that your container is using the same networking stack as your host machine. In other words,localhost:5000
on your laptop becomeslocalhost:5000
in the client container. This is not recommended, because it means that your ports are exposed on the host machine and could network with unintended services.