New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular import between container1 and container2 #666

Closed
jmreicha opened this Issue Nov 21, 2014 · 15 comments

Comments

Projects
None yet
10 participants
@jmreicha

jmreicha commented Nov 21, 2014

I am hitting an issue where I need 2 containers to be able to communicate with each other, ie one container needs to be able to ping the other and vice versa but when I add each container in to the links section of the fig.yml file I get a Circular import between container1 and container2 error when I run fig up.

Is there a workaround for this? Isn't the link section just adding an entry in each containers host file? If so, shouldn't that be allowed for containers to be able to communicate with each other?

Here is the bit causing problems. Obviously I have changed some of the names around.

container1:
  image: user/container1
  ports:
    - "8000:8000"
  links:
    - "container2:container2"

container2:
  image: user/container2
  ports:
    - "8080:8080"
  links:
    - "container1:container1"

Is there something I am missing here?

@cpuguy83

This comment has been minimized.

cpuguy83 commented Nov 21, 2014

Today, this doesn't work. The plan for linksv2 is to allow essentially this.
That said, in github.com/cpuguy83/docker-grand-ambassador you can create an ambassador container and each container can link to that..

so...

docker run -d --name amb -v /var/run/docker.sock:/var/run/docker.sock cpuguy83/docker-grand-ambassador -name container1 -name container2
docker run --name container1 -p 8000:8000 --link amb:container2 user/container1
docker run --name container2 -p 8080:8080 --link amb:container1 user/container2
@carterbancroft

This comment has been minimized.

carterbancroft commented Nov 21, 2014

Is this possible to do with fig? If so, would the following syntax be correct? I'm not completely sure how to specify that a container should run in detached mode within the fig yml.

ambassador:
    image: cpuguy83/docker-grand-ambassador
    volumes:
         - "/var/run/docker.sock:/docker.sock"
    name:
         - "container1"
         - "container2"

container1:
    image: user/container1
    ports:
        - "8000:8000"
    links:
        - "ambassador:container1"

container2:
    image: user/container2
    ports:
        - "8080:8080"
    links:
        - "ambassador:container2"
@cpuguy83

This comment has been minimized.

cpuguy83 commented Nov 21, 2014

Detached doesn't matter.

The "name" param is an argument to the command in the container.

@willdurand

This comment has been minimized.

willdurand commented Nov 27, 2014

@cpuguy83 would you have a reference config for docker-grand-ambassador with fig?

@carterbancroft

This comment has been minimized.

carterbancroft commented Nov 27, 2014

@willdurand here's what worked for me...

ambassador:
    image: cpuguy83/docker-grand-ambassador
        volumes:
            - "/var/run/docker.sock:/var/run/docker.sock"
    command: "-name figname_container1_1 -name figname_container2_1"

container1:
    image: user/container1
    ports:
        - "8000:8000"
    links:
        - "ambassador:container2"

container2:
    image: user/container2
    ports:
        - "8080:8080"
    links:
        - "ambassador:container1"
@willdurand

This comment has been minimized.

willdurand commented Nov 27, 2014

@alt234 came up with the same config, thanks!

@david-guenault

This comment has been minimized.

david-guenault commented Nov 28, 2014

another way should be to use a "service discovery" and automatic dns registration like skydock+skydns. This way no need to use links. Well except if you use multihosts (because skydock/skydns is not ready for that).

@mucsi96

This comment has been minimized.

mucsi96 commented Jun 6, 2015

You can create bidirectional links using a custom tiny DNS server. So instead of this

serviceb:
    image: username/serviceb

servicea:
    image: username/servicea
    links:
        - serviceb

Try this

dnsdock:
    image: tonistiigi/dnsdock
    volumes:
        - /var/run/docker.sock:/run/docker.sock
    ports:
        - 172.17.42.1:53:53/udp
serviceb:
    image: username/serviceb
    dns: 172.17.42.1

servicea:
    image: username/servicea
    dns: 172.17.42.1

You can access the services with: <container-name>.<image-name>.docker hostname. You can check <container-name> and <image-name> after docker-compose up in dnsdock logs. More details here

@dnephin

This comment has been minimized.

Contributor

dnephin commented Sep 1, 2015

This is being addressed in #1676

@dnephin dnephin closed this Sep 1, 2015

@dpwspoon

This comment has been minimized.

dpwspoon commented Nov 5, 2015

Sorry, late to the party. @dnephin, I still get circular dependency error in 1.9.0. Having read #1676 and network docs I don't yet have a suitable solution with out using work around listed above. Use case is two containers that load balance and cluster to each other.

Simplified yml

gateway-member1:
  image: gateway.ex.base
  links:
    - gateway-member2:cluster.member.com
  hostname: gateway.example.com
  command: gateway.start --config conf/gateway-cluster-config.xml
gateway-member2:
  image: gateway.ex.base
  links:
    - gateway-member1:cluster.member.com
  hostname: gateway.example.com
  command: gateway.start --config conf/gateway-cluster-config.xml

my versions

Client:
 Version:      1.9.0
 API version:  1.21
 Go version:   go1.4.3
 Git commit:   76d6bc9
 Built:        Tue Nov  3 19:20:09 UTC 2015
 OS/Arch:      darwin/amd64

Server:
 Version:      1.9.0
 API version:  1.21
 Go version:   go1.4.3
 Git commit:   76d6bc9
 Built:        Tue Nov  3 19:20:09 UTC 2015
 OS/Arch:      linux/amd64

docker-compose version: 1.5.0
docker-py version: 1.5.0
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1j 15 Oct 2014

I'd prefer to use just compose and docker with only my containers (No ambassador pattern, no DNS containers, no network plugins).

@dnephin

This comment has been minimized.

Contributor

dnephin commented Nov 5, 2015

Are you using the --x-networking flag to docker-compose ? Can you include the command you are running and the output ?

@dpwspoon

This comment has been minimized.

dpwspoon commented Nov 9, 2015

Thanks @dnephin, its working with the networking commands now! I was missing the flag. One question. Our application has a quirk for binding on clustering it assumes you know the interface name for the configuration (inherited by old hazelcast libraries). We are working on a patch on our end to configure it via domain names. In the mean time can we count on the interface names that the container sees as being deterministic?

docker-compose --x-networking -f jms.cluster.yml up
WARNING: 
Some services ("gateway-member1", "gateway-member2") define links, which are not compatible with Docker networking and will be ignored.
Future versions of Docker will not support links - you should remove them for forwards-compatibility.
@dnephin

This comment has been minimized.

Contributor

dnephin commented Nov 9, 2015

I'm not sure about that. From what I've seen it's always eth0, but I'm not sure that's a guarantee. There might be something about it in the docker networking docs.

@zx1986

This comment has been minimized.

zx1986 commented Dec 13, 2015

this issue is evil ...

@ei-grad

This comment has been minimized.

ei-grad commented Feb 5, 2016

Sad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment