Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlay network not found when running single docker on swarm worker #968

Open
david-baylibre opened this issue Sep 19, 2024 · 4 comments
Open
Labels
docker-plain plain Docker (no swarm, no compose, no stack) docker-swarm Docker Swarm

Comments

@david-baylibre
Copy link

SUMMARY

Overlay network can't be found error when creating a single docker container on a swarm worker part of the cluster.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.docker.docker_container

ANSIBLE VERSION
"2.12.10"
COLLECTION VERSION
# /usr/lib/python3/dist-packages/ansible_collections
Collection       Version
---------------- -------
community.docker 2.6.0  

# ~/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.docker 3.12.1
CONFIGURATION

OS / ENVIRONMENT

Linux Mint 20.3 Una
Linux 5.15.0-117-generic #127~20.04.1-Ubuntu SMP

STEPS TO REPRODUCE

I've set up a docker swarm cluster, host1 and host2 nodes being manager and worker respectively
I create a docker swarm network on the manager and try to create a single docker attached to that network on host2.

- hosts: host1
  become: true
  tasks:
    - name: create docker swarm network
      docker_network:
        name: test_net
        attachable: yes
        driver: overlay

- hosts: host2
  become: true
  tasks:
    - name: alpine
      community.docker.docker_container:
        name: alpine
        image: alpine
        state: started
        networks:
          - name: test_net
EXPECTED RESULTS

This should create the docker attached to test_net network
I use the shell module as a workaround which works just fine:

    - name: alpine
      ansible.builtin.shell:
        cmd: docker run -d --name alpine --network test_net alpine
ACTUAL RESULTS

The network is not found

TASK [alpine] ********************************************************************************************************************************************************************************************************************************
fatal: [host2]: FAILED! => {"changed": false, "msg": "Parameter error: network named test_net could not be found. Does it exist?"}
@felixfontein felixfontein added docker-swarm Docker Swarm docker-plain plain Docker (no swarm, no compose, no stack) labels Sep 19, 2024
@felixfontein
Copy link
Collaborator

docker_container does not know about Docker Swarm and that very likely won't change, so if the network isn't present on the Docker daemon you run it against, it will complain that the network does not exist.

@david-baylibre
Copy link
Author

So that's a docker_container implementation issue if I understand correctly?

Just for the record, "The --attachable option enables both standalone containers and Swarm services to connect to the overlay network" according to https://docs.docker.com/engine/network/drivers/overlay/

What do you recommend as a workaround? The shell module solution as above?
Thanks

@felixfontein
Copy link
Collaborator

It's basically a limitation of Docker. docker network ls will only find the network if it's already used by a container for the local daemon (or something like that, I don't use Swarm so I don't know the exact conditions). So the docker_container module - which doesn't know about Swarm - will not be able to find the network by its name.

As I don't use Swarm I can't say how to work around this.

@david-baylibre
Copy link
Author

I'll stick to the shell workaround then. As you mention, the network does show up once a container is attached to it on the local node.
Thanks for your feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker-plain plain Docker (no swarm, no compose, no stack) docker-swarm Docker Swarm
Projects
None yet
Development

No branches or pull requests

3 participants
@felixfontein @david-baylibre and others