1

I want a shell inside a Docker Service / Swarm network. Specifically, I want to be able to connect to a database that's inside the network.

From the manager node, I tried:

# docker network ls
NETWORK ID          NAME          DRIVER              SCOPE
481c20b4039a        bridge        bridge              local
2fhe9rtim9mz        my-network    overlay             swarm

Then

docker run -it --network my-network alpine sh

But I get the error:

docker: Error response from daemon: swarm-scoped network (event-data-core-prod) is not compatible with docker create or docker run. This network can only be used by a docker service.

Is it possible to somehow start an interactive session that can connect to a network service?

Joe
  • 46,419
  • 33
  • 155
  • 245
  • If you're using 1.13 there is an `--attachable` flag when creating a network that will let ad-hoc (non-service) containers join a network. – johnharris85 Feb 21 '17 at 21:12
  • Is there a way to change this for an extant network? Docs don't seem to suggest it. I don't want to stop a whole network just to edit this config value. https://docs.docker.com/engine/reference/commandline/network/ – Joe Feb 21 '17 at 22:04

1 Answers1

4

Since Docker Engine v1.13 (like already mentioned by johnharris85) it is possible for non-service container to attach to a swarm-mode overlay networks using the --attachable commandline parameter when creating the network:

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

Regarding your followup question:

Is there a way to change this for an extant network?

Yes and no, like I already described in another question you can make use of the docker service update feature:

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