0.0.0.0
is not a valid IP address. It is a notation to bind to all addresses, which is used in configuring the service that should listen.
Change your configuration to the IP address of the loopback interface.
location /api {
proxy_pass http://127.0.0.1:5000;
}
Regarging the docker containers: You can't reach a port on another container via localhost
by default. Every container has it's own network namespace, which is separated by the hosts. To reach one container from another you have three possibilities:
- host networking
- container links (legacy, will probably removed in the future)
- custom networks
Since custom networks are the most viable option I'll focus on this.
You need to create a network and reference it when you create containers.
docker network create my-network
docker run --network my-network --name db mariadb:latest
docker run --network my-network --name app -p 80:8080 myimage
now you can reference the container db
by its name from inside the app
container. You don't need to publish the ports in the db container, since they share the same network.
with docker-compose you don't need to do anything special when all containers that are involved are defined in the same yaml file, it creates a network for the containers by default.
If you have multiple yaml files and want to share a container, for example, a single database instance, you can reference it's network as an external network in the docker-compose.yml
.