将 docker-compose 与 docker swarm 一起使用 [英] Use docker-compose with docker swarm

查看:34
本文介绍了将 docker-compose 与 docker swarm 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 docker 1.12.1我有一个简单的 docker-compose 脚本.

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"

我用 docker-compose -p jenkins up -d 运行这个脚本.这将创建我的 2 个容器,但仅在我的主人上(从那里我执行我的命令).我希望在主节点上创建一个,在节点上创建一个.我也尝试添加

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

  networks:
     - jenkins_swarm

在每次服务之后,但这都失败了:

After every service but this is failing with:

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

当我执行 docker network ls

有人可以帮助我使用 docker-compose 在我的 2 个节点上部署 2 个容器.Swarm 肯定在我的集群"上工作.我按照教程进行验证.

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.

推荐答案

Compose 目前不支持 Swarm 模式.

Compose doesn't support Swarm Mode at the moment.

当您在主节点上运行 docker compose up 时,Compose 会为 Compose 文件中的服务发出 docker run 命令,而不是 docker service create - 这就是容器都在主服务器上运行的原因.见 这个回答选项.

When 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.

关于第二点,网络的范围在 1.12 中.如果您检查您的网络,您会发现它是在 swarm 级别创建的,但 Compose 正在运行无法看到 swarm 网络的引擎级容器.

On 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.

这篇关于将 docker-compose 与 docker swarm 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆