Home:ALL Converter>Use docker-compose with docker swarm

Use docker-compose with docker swarm

Ask Time:2016-10-05T21:39:33         Author:DenCowboy

Json Formatter

I'm using docker 1.12.1 I have an easy docker-compose script.

version: '2'

services:
  jenkins-slave:
    build: ./slave
    image: jenkins-slave:1.0
    restart: always
    ports:
     - "22"
    environment:
     - "constraint:NODE==master1"
  jenkins-master:
    image: jenkins:2.7.1
    container_name: jenkins-master
    restart: always
    ports:
     - "8080:8080"
     - "50000"
    environment:
     - "constraint:NODE==node1"

I run this script with docker-compose -p jenkins up -d. This Creates my 2 containers but only on my master (from where I execute my command). I would expect that one would be created on the master and one on the node. I also tried to add

networks:
  jenkins_swarm:
    driver: overlay

and

  networks:
     - jenkins_swarm

After every service but this is failing with:

Cannot create container for service jenkins-master: network jenkins_jenkins_swarm not found

While the network is created when I perform docker network ls

Someone who can help me to deploy 2 containers on my 2 nodes with docker-compose. Swarm is defenitly working on my "cluster". I followed this tutorial to verify.

Author:DenCowboy,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/39875575/use-docker-compose-with-docker-swarm
Elton Stoneman :

Compose doesn't support Swarm Mode at the moment. \n\nWhen you run docker compose up on the master node, Compose issues docker run commands for the services in the Compose file, rather than docker service create - which is why the containers all run on the master. See this answer for options.\n\nOn the second point, networks are scoped in 1.12. If you inspect your network you'll find it's been created at swarm-level, but Compose is running engine-level containers which can't see the swarm network.",
2016-10-05T13:56:36
yy