![docker network port mapping docker network port mapping](https://miro.medium.com/max/2260/1*pxgEmyU1LZIfHENlBmFDHQ.png)
You can achieve what you are trying to do by adding another container to the docker-compose.yaml, which will act as a reverse proxy in front of the barfoo container. The foobar container, however, is hitting the container port directly, which is listening on port 80 alone. We will try to access nginx on host port. Here, we pulled nginx image from the docker hub.
![docker network port mapping docker network port mapping](http://www.aquamarinechemicals.com/wp-content/uploads/2012/02/ports-map-uk-21.jpg)
![docker network port mapping docker network port mapping](https://miro.medium.com/max/1838/1*BgI9ju7ApJYjOlY_PAWx4g.png)
When you execute curl from your terminal, you are hitting the local port 8002 of your computer, which is forwarding port 80 of your container. Port forwarding enables access to applications running inside containers from outside world. Then foobar would connect to barfoo using service name and port barfoo:80 If that's really what you want, a better alternative would be to use docker stack.Īnd your services would be docker swarm services:ĭocker deploy -compose-file path_to_compose_file Hostname and both can use port 80 directly Where in production there is no port needed since they use a different The reason why is that I want to simulate a production like situation, foobar:īut then foobar would need to connect using localhost:8002 You can add network_mode: host to barfoo and foobar. However barfoo listens on port 80 inside the container and not on 8002. So when you run curl from foobar container you try to connect to service barfoo to port 8002. But that's probably not what you want.īarfoo is service name registered in internal docker dns accessible only by the services ( foobar) within the same docker network created when you run docker-compose up Simple solution is to map host port 8002 to barfoo port 8002. How can I make curl work from the foobar-container, without making changes to the docker file?