【发布时间】:2018-03-14 09:17:52
【问题描述】:
- 我运行 RancherOS 来运行 docker 容器
- 我在 GUI 上创建了一个容器来运行我的数据库(图像:mysql,名称:r-mysql-e4e8df05)。不同的容器使用它。
- 我可以在 GUI 上将其他容器链接到它
- 这次我想在 jenkins 上自动创建和启动一个容器,但是链接效果不好
我的命令:
docker run -d --name=app-that-needs-mysql --link mysql:mysql myimages.mycompany.com/appthatneedsmysql
我得到错误:
Error response from daemon: Could not get container for mysql
我尝试了不同的方法:
1)
--link r-mysql-e4e8df05:mysql
错误:
Cannot link to /r-mysql-e4e8df05, as it does not belong to the default network
2)
尝试使用--net 选项
正在运行:docker network ls
NETWORK ID NAME DRIVER SCOPE
c..........e bridge bridge local
4..........c host host local
c..........a none null local
-
--net none成功,但实际上它不起作用。该应用无法连接到数据库 - 带有
--net host错误信息conflicting options: host type networking can't be used with links. This would result in undefined behavior - 带有
--net bridge错误信息:Cannot link to /r-mysql-e4e8df05, as it does not belong to the default network
我还检查了运行这个 mysql 的 Rancher GUI:
它会得到一个continer IP 开头为:10.X.X.X
我也试过add --net managed,但报错:network managed not found
我相信我错过了在这个 docker 链接过程中的理解。 请给我一些想法,我怎样才能使这些工作。
(以前当我创建相同的容器并在 GUI 中链接到 mysql 时它正在工作)
【问题讨论】:
-
能分享一下你用来运行mysql的代码吗?
-
你可以很容易地做到这一点,而无需 racnher
-
检查我的这些答案,如果没有,请告诉我
标签: docker rancher docker-link