Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Containers defined in docker-compose.yml can't reach each other #328
If I run
version: '2' services: foo: image: alpine command: sleep 999999 bar: image: alpine command: sleep 999999
According to the documentation, the behaviour should be as follows:
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
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).
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
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!
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).
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.