14

I need to connect my db container with my server container. Now I just red about the legacy parameter --link, which works perfect

$> docker run -d -P --name rethinkdb1 rethinkdb
$> docker run -d --link rethinkdb:db my-server

But, if this parameter will be dropped eventually, how would I do something like the above ?

Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333
  • 1
    The docs say you should use [this](https://docs.docker.com/engine/userguide/networking/) instead. – jwodder Jan 05 '16 at 20:51
  • thanks a lot, I think I get it now. If you add two container to the same network, their `/etc/hosts` file is updated automatically, right – Jeanluca Scaljeri Jan 05 '16 at 21:29

1 Answers1

21

The docs says to use the docker network command instead (which is available since Docker 1.9.0 - 2015-11-03)

Instead of

$> docker run -d -P --name rethinkdb rethinkdb
$> docker run -d --link rethinkdb:rethinkdb my-server

you will now use

$> docker network create --name my-network
$> docker run -d -P --name rethinkdb1 --net=my-network rethinkdb
$> docker run -d --net=my-network my-server

Note that in the new form, container names are used, while before you were able to define an alias.

When two containers are part of the same network, their /etc/hosts file is updated so that you can use the container names instead of their IP addresses.

Thomasleveil
  • 95,867
  • 15
  • 119
  • 113
  • 4
    In docker version 18.06.1-ce `docker network create --name my-network` returns `unknown flag: --name` whereas `docker network create -my-network` seems to work just fine – Løiten Nov 13 '18 at 11:29