Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I connect directly to a docker swarm network?

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?

like image 555
Joe Avatar asked Jan 24 '26 23:01

Joe


1 Answers

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
    
like image 65
Murmel Avatar answered Jan 26 '26 17:01

Murmel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!