New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Containers defined in docker-compose.yml can't reach each other #328

Closed
mre opened this Issue Nov 3, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@mre
Copy link

mre commented Nov 3, 2017

If I run crane up with the following docker-compose.yml, the containers foo and bar can't reach each other:

version: '2'
services:
  foo:
    image: alpine
    command: sleep 999999
  bar:
    image: alpine
    command: sleep 999999
# crane exec foo ping bar
ping: bad address 'bar'

According to the documentation, the behaviour should be as follows:

By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.

Workaroud

By adding links between the containers, everything works as expected:

version: '2'
services:
  foo:
    image: alpine
    command: sleep 999999
    links:
      - bar
  bar:
    image: alpine
    command: sleep 999999
    links:
      - foo
# crane exec foo ping bar
PING bar (172.17.0.3): 56 data bytes
64 bytes from 172.17.0.3: seq=0 ttl=64 time=0.116 ms
64 bytes from 172.17.0.3: seq=1 ttl=64 time=0.129 ms
64 bytes from 172.17.0.3: seq=2 ttl=64 time=0.115 ms
@michaelsauter

This comment has been minimized.

Copy link
Owner

michaelsauter commented Nov 3, 2017

Yes, Crane differs from docker-compose here. It does not create a network by default, you'll need to define one. See https://www.craneup.tech/docs#networks. I should add to the documentation there that this is a big difference to docker-compose.

There are other differences, such as container prefixing by default (Crane doesn't do that, but docker-compose does).

@mre

This comment has been minimized.

Copy link

mre commented Nov 3, 2017

Ah okay. Coming from docker-compose I was kind of surprised by that. Maybe it could be the default behaviour if crane reads from a docker-compose.yml?

@michaelsauter

This comment has been minimized.

Copy link
Owner

michaelsauter commented Nov 3, 2017

Hmm, good idea. When I added docker-compose support to Crane I was thinking about adding this feature as a default for Crane, but something made me change my mind. If I'm not mistaken, it was because of the difference in prefixing.

Since docker-compose adds a prefix by default, it can always create a "default" network, which will be something like "foo_default". Crane doesn't prefix by default (I don't like that because it prevents you from running docker and crane commands interchangably), and then it becomes much harder to setup a default network.

One solution as you propose would be to detect reading from docker-compose, then enabling prefixing and default networks. I'll have to think about that. Thanks for the suggestion!

@michaelsauter

This comment has been minimized.

Copy link
Owner

michaelsauter commented Nov 16, 2017

Update:

  • I have updated the docs to make this clearer
  • I realised that compose also joins containers automatically

Thinking a bit more about this I am not sure whether I want to build this auto-magic "compose behaviour". This is going to lead to surprises when it works in one case, but not in another because detection fails (not sure what to base it on, file name sounds fragile).

@michaelsauter

This comment has been minimized.

Copy link
Owner

michaelsauter commented Nov 18, 2017

Thinking more about this and re-reading the documentation of docker-compose, I came to the conclusion to change Crane's behaviour once more, see https://github.com/michaelsauter/crane/blob/9d401120e32588e8a9759b46d47438e5852fc16e/CHANGELOG.md.

In short, a default network will be created by default, all containers will connect to it and can reach each other by name. Should be munch easier to use Crane and docker-compose interchangeably now.

I'm planning to update the docs and release a new version with this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment