
我的命令:
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 network2)
尝试使用--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,它是成功的,但实际上它不起作用。应用程序无法连接到DB。--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运行的牧场主GUI:

它得到一个continer IP起始蛋白: 10.X.X.X。
我也尝试过add --net managed,但是错误:network managed not found
我想我很怀念这个对接过程中的一些东西。,请给我一些想法,我怎样才能使这些工作。
(以前,当我创建同一个容器并链接到GUI中的mysql时,它是起作用的)
发布于 2018-03-20 11:13:39
乍一看,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.
可能解决办法
解决方法是创建一个用户自定义网桥和simpy,将您的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。我希望这能帮到你!
https://stackoverflow.com/questions/49273718
复制相似问题