NetworkHost and run one container on each node on Docker Swarm

Hello, I need to configure NetworkHost and a container to run on each node on Docker Swarm. Because I should forward 10000-2000 udp ports and some tcp ports. I searched a bit but couldn’t find anything. I can do this in Kubernetes, but I couldn’t find how to do it in docker. Is there any way to do it on Docker ?

Thanks.

Do you mean

docker run --network host image

?

You can use Docker Swarm which is a part of Docker.

Other option is using Ansible to deploy a container with the same configuration on muptiple server.

Thanks for your response. I need to run --network host on Docker Swarm. I can run on the Kubernetes. But could not find any solution on Docker Swarm side, i think, i m missing something.

I thought I missed that part in the title then I realized, you changed it :slight_smile: It is clear now. I don’t use swarm regurarly so I am not sure how you should do it if the network_mode doesn’t work in the stack file. There are others more familiar with swarm who will help you, I am sure. I will search for it too, later.

Update:

@mrmr2021

I found this:

You can also use a host network for a swarm service, by passing --network host to the docker service create command

Thanks again, i will try it.

Do you know how can i run a container on each node ?

Regards.

I searched for “docker swarm daemonset” since I also use Kubernetes more often.

  • You can specify whether the service needs to run a specific number of replicas or should run globally on every worker node. See Replicated or global services.
docker service create \
  --name myservice \
  --mode global \
  alpine top