docker-compose无法连接外网

docker-compose can't connect to external network

我已经创建了一个外部覆盖网络:

docker network create --driver overlay --subnet=10.0.9.0/24 mynetwork

网络创建成功:

$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
37295f249f91        bridge              bridge              local               
c2ec03c99888        docker_gwbridge     bridge              local               
33dd13c9686d        host                host                local               
27goixjy0jys        ingress             overlay             swarm               
75508732fab2        none                null                local               
ef6fti3kq6w4        mynetwork           overlay             swarm  

当我尝试将容器放入我的 docker-compose.yml 中时,服务创建失败

$ docker-compose up
Creating service-lb

ERROR: for service-lb  network mynetwork not found
ERROR: Encountered errors while bringing up the project.

我的 docker-compose.yml 看起来像这样:

version: "2"
services:
    service-lb:
        image: myreg:5000/myorg/service-lb:latest
        ports:
        - "0.0.0.0:10080:80"
        dns_search:
        - .
        networks:
        - mynetwork
networks:
    mynetwork:
        external: true

docker-compose是否无法处理群范围内的覆盖网络?

Versions:
docker-compose v1.8.0-rc2
docker 1.12.0-rc5

docker-compose 与 swarm 模式不兼容,因为它仍然使用容器 API,而 swarm 模式需要使用服务 API。我相信 1.12 中的覆盖网络只能在 swarm 模式下工作。所以是的,它们是不兼容的。

现在应该可以了。来自 https://docs.docker.com/compose/networking :

In v2.1+, overlay networks are always attachable. Starting in Compose file format 2.1, overlay networks are always created as attachable, and this is not configurable. This means that standalone containers can connect to overlay networks. In Compose file format 3.x, you can optionally set the attachable property to false.

您可能需要在 docker-compose 中声明您的网络:

external: true
driver: overlay