Docker 'link' feature will be deprecated as new feature 'networking' has been released (link). I'm making docker-compose with some containers, and it was fine with 'link' to connect each others(without any other commands).
Since I need to change link configuration to network, I have to make docker network before 'docker-compose up'. Is there any docker-compose feature that making docker network automatically? Or any other way to connecting each containers with some configuration?
By default, docker-compose with a v2 yml will spin up a network for your project. Any networks you define will also be created unless you explicitly tell it otherwise. Here's an example docker-compose.yml:
And then when you spin it up, you'll see that it creates the networks defined:
Note that linking containers also created an implicit dependency, so you may want to use
depends_on
in your yml to be explicit in any dependencies after removing your link.docker-compose creates a default network for your compose project on itself. You only have to migrate your compose projects to
version: '2'
orversion: '3'
of the compose yaml format. Please read how to upgrade for more information.With version 2 and 3, you don't have to specify links anymore, as all services will be in the default network if you don't explicitly specify other networks.
UPDATE: To make 2 containers talk to each other, you can simply use the service names which will resolve to container IPs. Links are now only required if for some reason a container expects a specific name, e.g. because it is hardcoded.