Docker Community Forums

Share and learn in the Docker community.

How do I link a single container to a running service?

docker

(Rdgacarvalho) #1

Hi everyone,

I have a question about new docker version 1.12 I’ve a cluster with one manager and two workers. I create a service with name appdomain sucessfully and now I’d like connect a new single container with then.

Is it possible?

docker service create --name appdomain --publish 8001:8001 jboss

docker run -tid --link node1:appdomain -p 8080:8080


(Tomasz Korwel) #2

Can you describe in more detail what you want to accomplish in this situation?

Even if linking as you described is possible it is highly risky solution. Keep in mind that docker’s orchestration can restart tasks at almost any time rendering your link inoperable. Without knowing more details I can only suggest creating two services and attaching them to their dedicated overlay network:

docker network create -d overlay my_overlay
docker service create --name appdomain --network my_overlay --publish 8001:8001 jboss
docker servise create --name newservice --network my_overlay --publish 8080:8080 

In this example both services will be able to communicate with each other by the service name (equivalent of --link) no matter where docker decides to run their underlying tasks.

Also if port 8001 on appdomain is only needed to communicate with the other container I would skip publishing it - within overlay network all ports are available to other containers and no publishing is needed.


(Thshaw) #3

Hey everyone, I was trying something similar. Running a redis service globally and wanted to populate it from a container. I don’t have any PR number or more details but this support is in progress.

“tomwillfixit there’s a PR on it’s way that will allow you to attach stand alone containers to a swarm overlay network, not sure if you can do it as it is today.”