使用码头组合与码头组群 [英] Use docker-compose with docker swarm

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

问题描述

我使用 docker 1.12.1
我有一个简单的docker-compose脚本。

 版本:'2'

服务:
jenkins-slave:
build:./slave
image:jenkins-slave:1.0
restart:always
ports:
- 22
environment:
- 约束:NODE == master1
jenkins-master:
image:jenkins:2.7.1
container_name:jenkins-master
重新启动:始终
ports:
- 8080:8080
- 50000
环境:
- 约束:NODE == node1

我使用 docker-compose -p jenkins up -d 运行此脚本。
这创建我的2个容器,但只在我的主(从我执行我的命令)。我会期望在主节点上创建一个,在节点上创建一个。
我也尝试添加

 网络:
jenkins_swarm:
驱动程序:overlay

 网络:
- jenkins_swarm

每次服务后,都会失败: p>

 无法创建服务的容器jenkins-master:network jenkins_jenkins_swarm not found 

当我执行 docker network ls



时,创建网络有人可以帮助我在Docker-compose的2个节点上部署2个容器。 Swarm正在对我的集群进行防御性的工作。我遵循教程进行验证。

解决方案

目前,撰写不支持Swarm Mode。



当您在主节点上运行 docker compose up 时,Compose发出 docker run 命令为Compose文件中的服务,而不是 docker服务创建 - 这就是为什么容器都在主服务器上运行。请参阅



第二点,网络范围在 1.12 中。如果您检查您的网络,您会发现它已经在群集级创建,但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"

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.

解决方案

Compose doesn't support Swarm Mode at the moment.

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.

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.

这篇关于使用码头组合与码头组群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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