How to connect to Docker bridge network from host?

Viewed 195

For a test project, I want to have the following network connectivity

                           +---------------------------+
                           | redis-service-1 in docker |
                           +-----------+ B +-----------+
                                       | R |
+--------+                             | I |
|  Host  |    --->                     | D |
+--------+                             | G |
                                       | E |
                           +-----------+   +-----------+
                           | redis-service-2 in docker |
                           +---------------------------+

What I want to achieve is for my app running on Host it should be able to connect to both of the Redis services running in two docker containers using the DNS routing given by docker.

docker-compose.yml looks like the following:

version: '3.6'
services:
  redis-service-1:
    image: redis:5.0
    networks:
      - overlay
  redis-service-2:
    image: redis:5.0
    networks:
      - overlay

Ideally after docker-compose up on the host I want to be able to ping both of the containers as following:

> redis-cli -h redis-service-1 ping

> redis-cli -h redis-service-2 ping

But I am unable to connect to these containers and Redis inside them from the host machine.

0 Answers
Related