Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose swarm: force containers to run on specific hosts

Trying to run cluster application on different virtual machines with use of Swarm stand alone and docker-compose version '2'. Overlay network is set. But want to force certain containers to run on specific hosts.

In documentation there is following advice, but with this parameter I was not able to start any container at all:

environment:
  - "constraint:node==node-1"

ERROR: for elasticsearch1  Cannot create container for service elasticsearch1: Unable to find a node that satisfies the following conditions
[available container slots]
[node==node-1]

Should we register hosts as node-1 node-2... or it is done by default.

[root@ux-test14 ~]# docker node ls
Error response from daemon: 404 page not found
[root@ux-test14 ~]# docker run swarm list
[root@ux-test14 ~]#  

[root@ux-test14 ~]# docker info
Containers: 8
 Running: 6
 Paused: 0
 Stopped: 2
Images: 8
Server Version: swarm/1.2.5
Role: primary
Strategy: spread
Filters: health, port, containerslots, dependency, affinity, constraint
Nodes: 2
 ux-test16.rs: 10.212.212.2:2375
  â ID: JQPG:GKFF:KJZJ:AY3N:NHPZ:HD6J:SH36:KEZR:2SSH:XF65:YW3N:W4DG
  â Status: Healthy
  â Containers: 4 (4 Running, 0 Paused, 0 Stopped)
  â Reserved CPUs: 0 / 2
  â Reserved Memory: 0 B / 3.888 GiB
  â Labels: kernelversion=3.10.0-327.28.3.el7.x86_64, operatingsystem=CentOS Linux 7 (Core), storagedriver=devicemapper
  â UpdatedAt: 2016-09-05T11:11:31Z
  â ServerVersion: 1.12.1
 ux-test17.rs: 10.212.212.3:2375
  â ID: Z27V:T5NU:QKSH:DLNK:JA4M:V7UX:XYGH:UIL6:WFQU:FB5U:J426:7XIR
  â Status: Healthy
  â Containers: 4 (2 Running, 0 Paused, 2 Stopped)
  â Reserved CPUs: 0 / 2
  â Reserved Memory: 0 B / 3.888 GiB
  â Labels: kernelversion=3.10.0-327.28.3.el7.x86_64, operatingsystem=CentOS Linux 7 (Core), storagedriver=devicemapper
  â UpdatedAt: 2016-09-05T11:11:17Z
  â ServerVersion: 1.12.1
Plugins:
 Volume:
 Network:
Swarm:
 NodeID:
 Is Manager: false
 Node Address:
Security Options:
Kernel Version: 3.10.0-327.28.3.el7.x86_64
Operating System: linux
Architecture: amd64
CPUs: 4
Total Memory: 7.775 GiB
Name: 858ac2fdd225
Docker Root Dir:
Debug Mode (client): false
Debug Mode (server): false
WARNING: No kernel memory limit support
like image 626
user3292147 Avatar asked Sep 05 '16 08:09

user3292147


People also ask

How do you change the leader on a Docker Swarm?

But, to answer your question, there is no way to manually set the swarm leader. However, what you can do is docker node demote the leader (swarm2), and the other manager (swarm3). Once the managers are demoted to workers, swarm1 by default becomes the leader.

Is Docker swarm being deprecated?

Docker Swarm is not being deprecated, and is still a viable method for Docker multi-host orchestration, but Docker Swarm Mode (which uses the Swarmkit libraries under the hood) is the recommended way to begin a new Docker project where orchestration over multiple hosts is required.

Is Docker swarm discontinued?

Important note: At the time of this writing, Docker Swarm is not dead. It is included in the Docker Community edition and Docker has not announced plans to deprecate it.

What do you need to run containers on multiple hosts?

Helios allows you to manage the deployment of Docker containers across multiple hosts. It gives you a single command-line interface that you can use to specify what you want to run and where to run it, as well as the ability to take a look at the current state of play.


1 Answers

My first answer is about "swarm mode". You'd since clarified that you're using legacy Swarm and added more info, so here:

The constraint you list assumes that you have a host named node-1. Your hosts are named ux-test16.rs and ux-test17.rs. Just use that instead of node-1 in your constraint. Eg:

environment:
  - "constraint:node==ux-test16.rs"
like image 93
Bernard Avatar answered Oct 19 '22 06:10

Bernard