Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: cannot link containers in --net=host mode

I have a Couchbase server container named db launched with --net=host option which exposes port 11210, and now I have to link another container to it. If I use the --link option while running my new container, that is type:

docker run -d -P --name my_name --link db:db my_image

I get:

Error response from daemon: Conflicting options: host type networking can't be used with links. This would result in undefined behavior.

How can I solve this?

like image 655
SegFault Avatar asked Apr 11 '17 15:04

SegFault


1 Answers

You can't.

"Linking" containers doesn't make any sense when using --net=host. When you link containers, Docker creates entries in /etc/hosts so that the containers can connect to each other by name, but when using --net=host your containers do not have unique addresses. They are sharing the host network environment.

You can just use localhost to access services running in either container, or any valid address on your host (assuming that your service is configured to listen on all available addresses).

like image 105
larsks Avatar answered Oct 13 '22 06:10

larsks