skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    It turns out that the network IS blocking ICMP, which was the cause of all my confusion here! There is no issue with the setup.


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search