Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to link existing containers with docker?

Tags:

docker

Can I create a container using docker run <image> without the --link option and link other containers to it afterwards? If so, how do I link these containers then?

like image 225
Jan Wy Avatar asked Aug 12 '14 10:08

Jan Wy


People also ask

Can two Docker containers use the same port?

Surprisingly or not, neither Docker nor Podman support exposing multiple containers on the same host's port right out of the box. Example: docker-compose failing scenario with "Service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash."

Can a Docker container start another container?

It is possible to grant a container access to docker so that it can spawn other containers on your host. You do this by exposing the docker socket inside the container, e.g: docker run -v /var/run/docker. sock:/var/run/docker.


1 Answers

Thats how you normally would do it. Fire up container A and start container B with --link B:resourcename. Inside container B, you can now get to the stuff container A EXPOSEs, with the info you can see inside the environment-variables env (they will be named something with resourcename in this case.

You can not do this the other way around (as I thought your question was originally about). The information the container needs to get to resources on the other is available as environment-variables. Which you cant inject into a running process (as far as I know..).

like image 112
xeor Avatar answered Oct 18 '22 20:10

xeor