Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
What's the easiest way to make containers started with docker-compose accessible from the host machine?
I have a simple docker-compose.yaml:
services:
redis-cluster1:
image: grokzen/redis-cluster:5.0.12
ports:
- "7000-7007:7000-7007"
redis-cluster2:
image: grokzen/redis-cluster:5.0.12
ports:
- "7010-7017:7000-7007"
redis-cluster3:
image: grokzen/redis-cluster:5.0.12
ports:
- "7020-7027:7000-7007"
and want to be able to hit those clusters from a non-docker process on the machine.
I've just read three articles and still can't get this to work.
Using 'docker container inspect' I'm able to see the IP of one of them:
"IPAddress": "172.19.0.3"
But it is not pingable.
Is this possible with the default bridge? This is on MacOS; can't use Linux-specific features.
–
By default when you create a new network of containers with docker-compose these are connected to a host network which allows each container to reach the external network (documentation). If you specify (like in your code) the port attribute for a container, this will tell to compose to expose the given port of the container to the network (Notice: this will expose such port not only to your localhost, but also to other machines connecting to your host ip). To sum up, with the proposed configuration you can reach for example redis-cluster1 on ports 7000-7007 from your localhost.
–
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.