Docker: what is the equivalent of the legacy --link parameter

时光毁灭记忆、已成空白 提交于 2020-01-01 04:40:05

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/34620695/docker-what-is-the-equivalent-of-the-legacy-link-parameter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!