我的命令:
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
它获得continer IP
启动:10.X.X.X
我还尝试add --net managed
,但错误:network managed not found
我相信我想念这个docker链接过程中的某些内容。 请给我一些想法,我该怎样才能完成这些工作。
(之前它在我创建相同的容器并链接到GUI中的mysql时工作)
答案 0 :(得分:2)
嘿@Tomi,您可以在牧场主的任何端口上公开mysql容器。这样您就不必链接容器,然后您的jenkins衍生容器连接到主机上公开端口上的容器。你也可以使用jenkins在牧场主中使用牧场主cli来旋转容器。你没有必要在主机网络上展示mysql ......有几种方法可以用牧场主去除那只猫。
答案 1 :(得分:0)
乍一看,Rancher似乎使用托管网络,docker network ls
未显示。
我使用虚拟高山容器来重现这个:
# create some network
docker network create your_invisible_network
# run a container belonging to this network
docker container run \
--detach \
--name r-mysql-e4e8df05 \
--net your_invisible_network \
alpine tail -f /dev/null
# trying to link this container
docker container run \
--link r-mysql-e4e8df05:mysql \
alpine ping mysql
确实我得到docker: Error response from daemon: Cannot link to /r-mysql-e4e8df05, as it does not belong to the default network.
解决方法是创建一个user-defined bridge network并简单地添加你的mysql容器:
# create a network
docker network create \
--driver bridge \
a_workaround_network
# connect the mysql to this network (and alias it)
docker network connect \
--alias mysql \
a_workaround_network r-mysql-e4e8df05
# try to ping it using its alias
docker container run \
--net a_workaround_network \
alpine \
ping mysql
# yay!
PING mysql (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.135 ms
64 bytes from 127.0.0.1: seq=1 ttl=64 time=0.084 ms
正如您在输出中所看到的那样,可以通过DNS名称查看mysql容器。
--link
容器即可开箱即用:)your_invisible_network
和a_workaround_network
我希望这有帮助!