Answers: <ul>
  <li>To ensure that Jenkins deploys containers on worker nodes instead of the manager node in your Docker Swarm, you can use the following approach:</li>
  </ul>
  <h3>Label the Worker Nodes</h3>
  <p>Assign a <strong>label</strong> to your worker nodes. This label will be used to specify where the containers should be deployed. On your <strong>manager</strong> node,</p>
  <pre class="lang-bash prettyprint-override"><code>docker node update --label-add worker=true &lt;worker-node-id&gt;
  </code></pre>
  <h3>Update Jenkins Configuration</h3>
  <p>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.</p>
  <h3>Use Docker Swarm Plugin</h3>
  <p>Ensure you are using the <strong>Docker Swarm plugin</strong> for Jenkins, which allows you to specify constraints for where the containers should be deployed.</p>
  <pre><code>agent {
      docker {
          image 'your-docker-image'
          label 'worker=true'
          args '-v /tmp:/tmp'
      }
  }
  </code></pre>
  <p>More information here :
  <a href="https://docs.docker.com/engine/swarm/how-swarm-mode-works/nodes/" rel="nofollow noreferrer">https://docs.docker.com/engine/swarm/how-swarm-mode-works/nodes/</a></p>
  <p><strong>PS</strong> : Know that the managers are workers by default.</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-08-16T15:59:13.717Z
Answers: 2024-08-16T15:59:13.717Z
Answers: YassineLbk
Body: <p>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:</p>
  <pre><code>docker node update --availability drain &lt;manager-id&gt;
  </code></pre>
  <p>The manager has the /usr/lib/systemd/system/docker.service set to start with:</p>
  <pre><code>ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock
  </code></pre>
  <p>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 &quot;docker&quot;, and provided the manager IP address as the docker host uri, eg. <code>tcp://a.b.c.d:2375</code>.</p>
  <p>There is no error, but when I start a job, it creates a container on the manager itself.</p>
  <p>How can I make it so that each container is deployed on a non-manager container?</p>
  
Tags: <docker><jenkins><docker-swarm>
Title: Using docker-swarm with Jenkins for deploying agents
UserDisplayName: DevOps
ThreadText: # Using docker-swarm with Jenkins for deploying agents
  
  (Asked by: username_0 on 2024-05-07)
  
  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?
  
  **Tags:** docker, jenkins, docker-swarm
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-08-16. Score: 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,
  
  ```bash
  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.
  
  
  ---
  
  