Christian Bongiorno
Christian Bongiorno

Reputation: 5648

Docker can't connect to container on bridge interface

I am trying to setup a compose file to support a legacy application. Said legacy app needs to connect to up to 3 DBs (MySQL). The problem is I can't change the port specification. I mean, I probably could, but we want to containerize everything without having to change any code.

when I run docker inspect on one of my containers I get:

 "IPAddress": "172.18.0.2",

which is good. But when I attempt to connect from my MAC I get timeout. In the past, I have had to make a network alias like such:

sudo ifconfig lo0 alias 10.200.10.1/24

But, it doesn't seem to help

$ docker -v
Docker version 17.06.2-ce, build cec0b72

mac:

$ uname -a
Darwin wa-cbongiorno-mba.local 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

Here is the compose file I am working with:

version: '3.3'
services:
  db1:
    image: mysql:5.6
    ports:
      - 3306
    environment:
      - MYSQL_ROOT_PASSWORD=my-secret-pw
    volumes:
      - ./Schema/db1:/docker-entrypoint-initdb.d/:ro
  db2:
    image: mysql:5.6
    ports:
      - 3306
    environment:
      - MYSQL_ROOT_PASSWORD=my-secret-pw
    volumes:
      - ./Schema/db2:/docker-entrypoint-initdb.d/:ro

Upvotes: 0

Views: 2542

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146630

If you read the documentation, this is not possible as of now on mac

Known Limitations, Use Cases, and Workarounds

Following is a summary of current limitations on the Docker for Mac networking stack, along with some ideas for workarounds.

There is no docker0 bridge on macOS

Because of the way networking is implemented in Docker for Mac, you cannot see a docker0 interface in macOS. This interface is actually within HyperKit.

I cannot ping my containers

Unfortunately, due to limitations in macOS, we’re unable to route traffic to containers, and from containers back to the host.

Per-container IP addressing is not possible

The docker (Linux) bridge network is not reachable from the macOS host.

Use cases and workarounds

There are two scenarios that the above limitations will affect:

I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST

The Mac has a changing IP address (or none if you have no network access). From 17.06 onwards our recommendation is to connect to the special Mac-only DNS name docker.for.mac.localhost which will resolve to the internal IP address used by the host.

I WANT TO CONNECT TO A CONTAINER FROM THE MAC

Port forwarding works for localhost; --publish, -p, or -P all work. Ports exposed from Linux are forwarded to the Mac.

Our current recommendation is to publish a port, or to connect from another container. Note that this is what you have to do even on Linux if the container is on an overlay network, not a bridge network, as these are not routed.

Upvotes: 2

Related Questions