0

I have a cluster which is being used as a docker swarm with one manager, and one worker. The manager node is a pure manager node, set via:

docker node update --availability drain <manager-id>

The manager has the /usr/lib/systemd/system/docker.service set to start with:

ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock

Now, I am trying to use this swarm cluster as a Jenkins cloud provider, so that all jobs run in docker containers. In Jenkins, under Configure Clouds, I have create a cloud provider of type "docker", and provided the manager IP address as the docker host uri, eg. tcp://a.b.c.d:2375.

There is no error, but when I start a job, it creates a container on the manager itself.

How can I make it so that each container is deployed on a non-manager container?

1 Answer 1

0
  • To ensure that Jenkins deploys containers on worker nodes instead of the manager node in your Docker Swarm, you can use the following approach:

Label the Worker Nodes

Assign a label to your worker nodes. This label will be used to specify where the containers should be deployed. On your manager node,

docker node update --label-add worker=true <worker-node-id>

Update Jenkins Configuration

In Jenkins, configure the Docker cloud provider to use the label you assigned to the worker nodes. This ensures that Jenkins will only deploy containers on nodes with the specified label.

Use Docker Swarm Plugin

Ensure you are using the Docker Swarm plugin for Jenkins, which allows you to specify constraints for where the containers should be deployed.

agent {
    docker {
        image 'your-docker-image'
        label 'worker=true'
        args '-v /tmp:/tmp'
    }
}

More information here : https://docs.docker.com/engine/swarm/how-swarm-mode-works/nodes/

PS : Know that the managers are workers by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.