- 我使用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
I tried different things:
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
它获得一个以10.X.X.X开头的容器IP
我也尝试了添加--net managed
,但是出现错误:network managed not found
我相信我在docker链接过程中有些误解。请给我一些想法,如何使这些工作。
(以前当我创建相同的容器并链接GUI中的mysql时,它是有效的)