网站可在独立容器中使用,而不能以群集方式使用 [英] Website available in standalone container, not in swarm

查看:77
本文介绍了网站可在独立容器中使用,而不能以群集方式使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows Server 2016上运行的Docker CE包含2个映像.

I have Docker CE running on windows server 2016 with 2 images.

当我在容器中运行它们时,一切都很好.

when I run these in containers, everything is fine.

docker run --detach --name Website1 --publish 94:94 webimage1
docker run --detach --name Website2 --publish 95:95 webimage2

我可以通过其他PC上的浏览器进行访问:

I can access through browser on other PCs:

现在我想成群地运行它们.

Now I want to run them in swarm.

我已经阅读了docker教程,并设置了docker-compose文件,服务和端口映射.该设置具有1个副本的网站1,2个副本的网站2.

I've gone through docker tutorial and 've set up docker-compose file, with services, port mapping. The setup has Website 1 of 1 replica, Website 2 of 2 replicas.

docker stack services网站上的端口号如下所示.

On docker stack services websites port numbers show up as follows.

Website1: *:94->94/tcp
Website2: *:95->95/tcp

但是我无法使用以下网址访问其中的任何一个:

but i can't access any of them with following url's:

我知道了-无法访问此网站

如果我回到正在运行的容器之一,则看到端口号具有不同的格式.

If I go back to one of my running containers, I see that the port number has a different format.

0.0.0.0:94->94/tcp (WORKING) VS *:94->94/tcp (NOT WORKING)

为初始化docker swarm,我使用 docker swarm init 和端口2377上主机的IP地址.

For initilizing docker swarm I used docker swarm init with IP address of the host on port 2377.

这是我使用撰写文件部署Docker堆栈的方式

Here is how I deployed docker stack using compose file

docker stack deploy --compose-file docker-stack.yml websites

docker-stack.yml 文件作为参考.

version: "3"
services:

  website1:
    image: website1:latest
    ports:
      - 94:94
    depends_on:
      - website2
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 3
        window: 120s
  website2:
    image: website2:latest
    ports:
      - 95:95
    deploy:
      mode: replicated
      replicas: 2
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 3
        window: 120s

任何指导将不胜感激.

非常感谢

推荐答案

在注释中的对话中,问题出在堆栈上.

From the conversations in the comments the problem is with the stack.

Docker堆栈仅支持用于部署和副本的映像.我相信您的图片是自定义的,既不在dockerhub中,也没有任何私人仓库中.因此,当您尝试将其部署在堆栈中时,正在工作者节点中部署的服务找不到该映像,并且无法从回购中下载它.因此,该服务将不会在工作程序节点中启动.它在管理器节点中完美运行,因为该图像已经存在于该节点中.

Docker stack supports only images for deployment and replicas. I believe your images are custom ones which are neither in dockerhub nor in any private repo. So when you try to deploy it in stack the service which is getting deployed in the worker node doesn't find such image and is unable to download it from repo. Hence the service won't start in worker node. It works perfectly in manager node because the image already exists there.

因此,您必须设置本地/私有注册表或将映像推送到docker注册表,否则甚至可以使用 docker save将映像从管理器节点复制到工作节点. docker load ,然后尝试使用swarm并将其部署在堆栈中将起作用.

So, you have to either set up a local/private registry or push the images to docker registry or else you can even copy the images from manager node to worker node using docker save and docker load and then try using swarm and deploy in stack it will work.

请注意在使用群集和注册表时,使用 docker stack deploy -c composefile.yml test 部署堆栈时,您必须通过-with-registry-auth 如果您将身份验证用作Docker堆栈的 docker stack deploy -c composefile.yml test --with-registry-auth ,否则其他节点可能无法通过注册表进行身份验证,否则将导致下载映像失败成立.

Please note when working with swarm and registries, While deploying stack using docker stack deploy -c composefile.yml test you have to pass --with-registry-auth if you are using authentication for registries as docker stack deploy -c composefile.yml test --with-registry-auth else other nodes may not authenticate with the registry which will result in failure to download images if not found.

还请注意,如果您设置的本地私有存储库没有自签名证书或自签名证书,则可能需要配置不安全的注册表.我已经给出了相同的参考.

Also please note if you set up a local private repo without self signed certificate or with self signed certificate you may need to configure insecure registry. I've given reference of the same.

我建议设置没有任何身份验证和证书的本地存储库,并通过在daemon.json文件中添加不安全的注册表进行访问以进行测试.

I recommend setting up a local repo without any authentication and certificates and access it by adding insecure registry in daemon.json file for testing purposes.

现在按照最后一条注释,在该注释中,您删除了swarm并尝试使用

Now as per the last comment where you removed swarm and tried running docker service using

docker服务create --replicas 2 --name contentlinksapi --publish mode = host,target = 94,published = 94,protocol = tcp contentlinksapi

它抛出了已在使用的端口,因为它试图在同一台计算机上创建2个副本.因此,第一个副本绑定到端口94的位置,第二个副本抛出已使用端口的错误.

It throwed port already in use because it tries to create 2 replicas in the same machine. Where the first replica binds to port 94 because of which, The second replica throws port already in use error.

供您参考.

  1. 部署注册表服务器
  2. 测试不安全的注册表
  3. Docker服务模式(检查以了解为什么具有两个副本的服务部署在 docker service create )的同一主机上
  4. Docker保存
  5. Docker加载
  1. Deploy a registry server
  2. Test an insecure registry
  3. Docker service mode (check to know why services with two replicas deployed in same host on docker service create)
  4. Docker save
  5. Docker load

这篇关于网站可在独立容器中使用,而不能以群集方式使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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