35

I'm trying to run a one-off command to initialise a database schema in a new docker swarm which is deployed with 1.13's new support for docker-compose files.

The swarm has the following network:

$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
...
b7dptlu8zyqa        vme_internal         overlay             swarm
...

defined in the docker-compose.yml file as:

networks:
    internal:

The command I run is

docker run --rm --network vme_internal app:0.1 db upgrade

with the extra vme_ prefix coming from the name that I gave the stack when deploying. Now when I run the above command, I get:

docker: Error response from daemon: Could not attach to network vme_internal:
rpc error: code = 7 desc = network vme_internal not manually attachable.

How do I make the network attachable?

I couldn't find any specific info about attachable in Docker networking and tried adding an attribute attachable to the network definition without success.

sas
  • 7,017
  • 4
  • 36
  • 50

2 Answers2

70

Using composer

Since composer v3.2 it is possible to configure the attachable property through the composer file using the keyword attachable like:

networks:
  mynet1:
    driver: overlay
    attachable: true

Using docker network create

Since Docker Engine API v1.25 it is possible to create a network and make it attachable using the --attachable parameter like:

docker network create --driver overlay --attachable my-overlay-network

To update an already running docker service:

  1. Create an attachable overlay network:

    docker network create --driver overlay --attachable my-attachable-overlay-network
    
  2. Remove the network stack with a disabled "attachable" overlay network (in this example called: my-non-attachable-overlay-network):

    docker service update --network-rm my-non-attachable-overlay-network myservice
    
  3. Add the network stack with an enabled "attachable" overlay network:

    docker service update --network-add my-attachable-overlay-network myservice
    
Murmel
  • 5,402
  • 47
  • 53
  • 10
    Please note that if you're stack was already deployed, just updating the network config won't be enough. You will need to remove the stack and deploy it again as network are not tracked for changes and are created only on initial deployment. – Matt Feb 28 '18 at 22:47
  • I do not understand your answer properly. If you have a swarm running, and you have different docker-compose.yml on different swarm workers, how than you can attach to the overlay network? By default you will only have ingress network in a swarm scope. – creed Jul 09 '19 at 10:53
6

By default, overlay networks created with the new swarm mode cannot be used with containers not run from swarm. Version 1.13 allows you to toggle this setting, so make sure you've upgraded. You must create the network with the attachable flag. I also couldn't get this to work on a swarm worker, the node needed to be promoted to a swarm manager.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • 1
    This is on 1.13 actually. How do I create an attachable network? Is this possible via the compose file or do I need to create the network externally and declare it as such in the compose file? – sas Jan 25 '17 at 11:00
  • I don't believe compose has support for that. You can deploy a stack using the compose file, which uses swarm and avoids the need to be attachable. Or you can define the network in advance and make it external in your compose file. – BMitch Jan 25 '17 at 11:03
  • 1
    It's now possible from compose definition directly, see answer below: https://stackoverflow.com/a/48404258/697930 – Matt Feb 28 '18 at 22:46