Weave: using weave with docker-compose

Created on 23 Dec 2015  路  14Comments  路  Source: weaveworks/weave

Is there a way to use weave with docker-compose?

e.g.

docker-compose yaml:

    mysql:
      restart: always
      image: mysql:latest
      container_name: mysql
      ports:
        - "3306"
      environment:
        - MYSQL_ROOT_PASSWORD=root

run:
docker-compose -f mysql.yml up -d

question

Most helpful comment

If you've launched weave already, and set the DOCKER_HOST environment variable, then containers started via docker-compose will all be connected to the Weave network.

Something like:

weave launch [other hostnames here]
eval $(weave env)
docker-compose -f mysql.yml up -d

All 14 comments

Yes, we have show this in our Docker Platform guide. It hasn't been updated to use the plugin yet, but I've started working on that.

yes I saw this, however I didn't really want to use docker swarm/machine

yes I saw this, however I didn't really want to use docker swarm/machine

Ah, okay. Life is much easier then!

All you need to care about is run eval $(weave env) before running docker-compose up.

If you wanna use DNS, you will need to set hostname: myservice.weave.local in you docker-compose.yml, e.g.:

    mysql:
      hostname: mysql.weave.local
      restart: always
      image: mysql:latest
      container_name: mysql
      ports:
        - "3306"
      environment:
        - MYSQL_ROOT_PASSWORD=root

If you've launched weave already, and set the DOCKER_HOST environment variable, then containers started via docker-compose will all be connected to the Weave network.

Something like:

weave launch [other hostnames here]
eval $(weave env)
docker-compose -f mysql.yml up -d

magic, I was missing the hostname - all is good now! Thanks :+1:

magic, I was missing the hostname - all is good now! Thanks :+1:

Brilliant! Glad we got there quickly :)

Note that now it would not work without the network_mode: "bridge" key:

version: '2'
services:
    a1:
        image: "weaveworks/ubuntu"
        hostname: a1.weave.local
        container_name: a1
        network_mode: "bridge"
        command: [tail, -0f, /etc/hosts]
networks:
    default:
        external:
            name: weave

Found it there: https://github.com/weaveworks/guides/blob/master/weave-and-docker-platform/app/docker-compose.yml

If you have network_mode: "bridge" then you shouldn't need the networks: stanza.

@rade you are right. fixed it in my comment.

Now I'm trying to figure out how to use it with two networks: the default for wave and another one for local one, like this (note that this file is incorrect!):

version: '2'
services:
    a1:
        image: "weaveworks/ubuntu"
        hostname: a1.weave.local
        container_name: a1
        network_mode: "bridge"
        command: [tail, -0f, /etc/hosts]
        networks:
            default:
                network_mode: "bridge"
            private_net:
    b1:
        image: "weaveworks/ubuntu"
        container_name: b1
        command: [tail, -0f, /etc/hosts]
        networks:
            - private_net
networks:
    default:
        external:
            name: weave
    private_net:

I think you want option 4 from https://github.com/weaveworks/guides/issues/187#issuecomment-228901173.

It states that it requires a docker cluster. I have plans to use it in my configuration. Second point is that it forces me to create new wave network instead of using the pre-created one. The third point is that if I want to use WeaveDNS, I need to specify dns and dns_search keys same as from the command weave dns-args. In my case it is:

--dns=172.17.0.1 --dns-search=weave.local.

I'm not sure that specifying things like 172.17.0.1 is appropriate, because one day it can change to something else.

So, I'm totally agree with you - the guide to use weave with docker-compose in a non-trivial cases is absolutely required.

Now I'm going to use this config:

version: '2'
services:
    a1:
        image: "weaveworks/ubuntu"
        hostname: a1.weave.local
        container_name: a1
        network_mode: "bridge"
        command: [tail, -0f, /etc/hosts]
    b1:
        image: "weaveworks/ubuntu"
        container_name: b1
        command: [tail, -0f, /etc/hosts]
networks:
    default:
        external:
            name: weave

This way I have a "published" service a1 and "internal" service b1. It has a drawback that the b1 service can be reached from outside by it's IP-address. I'm steel in a hope to have a not so "rocket science" technique to achieve the really local ("hidden") services behavior with weave and docker-compose.

just found that I can not ping a1 from the b1 container with this configuration. It seems that the only simple way is to "publish" all containers to the weave with hostname: key. Open for better suggestions.

Was this page helpful?
0 / 5 - 0 ratings