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?
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."
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.
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 EXPOSE
s, 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..).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With