How to force a service to run on specific host

Hello everybody,

I just want to know how to do in my docker-compose to force a service to run on a specific rancher host.
I’ve heard about labels, i’ve applied labels to my nodes but it doesn’t work.

I have 3 nodes : s01.xx.domain.com / s02.xx.domain.com / s03.xx.domain.com
Label for node 1 : id=s01
Label for node 2 : id=s02
Label for node 3 : id=s03

This is what i’ve tried :

version: '2'
services:
   jenkins:
 build: http://docker/jenkins/Dockerfile
 volumes:
  - /home/jenkins:/var/jenkins_home
 ports:
   - 8080:8080
   - 50000:50000
 labels:
  io.rancher.scheduler.global: 'true'
  io.rancher.scheduler.affinity:host_label: id=s02

What i’ve missed ? :confused:

Many thanks to any body who will help me :slight_smile:

Maybe just try indenting it more? Do they show up under the “Labels” section on the service, container, and host?

version: '2.0'
services:
  jenkins:
    build:
      context: http://docker/jenkins/Dockerfile
    labels:
      io.rancher.scheduler.affinity:host_label: id=s02
      io.rancher.scheduler.global: 'true'
    ports:
    - 8080:8080
    - 50000:50000
    volumes:
    - /home/jenkins:/var/jenkins_home:rw

Hi guy,

thank for your reply.

It don’t work with more identation.
What do you mean by "Do they show up under the labels section on the service " ?

I can see the label with the GUI on the nodes, but that’s all

Thanks

So, when you click a host’s ‘:’ menu and select ‘View in API’ you see:

-labels: {
...
id: "s02",
...

right?

What do you mean by “it doesn’t work?” Does the container end up being started on whatever host?

Additionally, when you select that container’s stack’s ‘:’ menu and click ‘View Config’ do you see your label in it? This will tell you whether your compose file was correctly parsed.

Hello,

Thank for your reply.

What do you mean by “it doesn’t work?” Does the container end up being started on whatever host?

yes exactly.

Additionally, when you select that container’s stack’s ‘:’ menu and click ‘View Config’ do you see your label in it? This will tell you whether your compose file was correctly parsed.

No i can’t see the label in it. So maybe my compose file is not correctly parsed as u said but i don’t know why.

EDIT : Hmm … finally i can see it in the config of the stack
EDIT 2 : Oh god it works with " on the label !

version: '2’
services:
jenkins:
build: http:/docker/jenkins/Dockerfile
labels:
io.rancher.scheduler.affinity:host_label: "id=s02"
io.rancher.scheduler.global: 'true’
ports:
- 8080:8080
- 50000:50000
volumes:
- /home/jenkins:/var/jenkins_home:rw