【问题标题】:getting Detected task failure for some images while creating docker service在创建 docker 服务时检测到某些图像的任务失败
【发布时间】:2018-11-09 08:55:32
【问题描述】:

我正在尝试创建 docker swarm 服务,但出现了一些奇怪的行为:

对于某些图像,它是成功的,对于某些图像,我收到错误:

docker service create nginx 89t21k3udf007pvl2ucvmdp9l overall progress: 1 out of 1 tasks 1/1: running [==================================================>] verify: Service converged --> 成功

docker service create hello-world 8hhdki32ypfwshh2wvijkkmvb overall progress: 0 out of 1 tasks 1/1: preparing [=================================> ] verify: Detected task failure --> 失败

供您参考:docker pull hello-world 工作正常。

我的印象是我们可以在所有图像上创建服务,是否有任何条款和条件?我错过了什么吗?

注意:这是基本部分,但我的主要目的是为本地注册表映像创建服务。但是在调试发现问题的第一步,即 hello-world。

【问题讨论】:

  • 您可以使用docker service inspect hello-worlddocker service ps hello-world --no-trunc 获取有关您的服务的更多详细信息。这应该可以帮助您诊断问题。
  • 你可以为 hello-world image 创建服务吗?

标签: docker docker-swarm docker-swarm-mode


【解决方案1】:

它失败了,因为从 hello-world Docker 映像创建的容器只显示一条消息然后退出,而且这种情况很快发生。

而且由于您创建了一个 swarm 服务,它会在每次失败时不断重新创建容器,这是意料之中的,这就是服务似乎失败的原因。

请查看下面的服务日志,您会看到容器不断被重新创建:

[ ~]$ docker service create --name helloworld hello-world iilsd1yc706zgcdg35l8sdz3z
Since --detach=false was not specified, tasks will be created in the background.
In a future release, --detach=false will become the default.

[ ~]$ docker service logs helloworld  -f
helloworld.1.jxxnqzximfy7@    |
helloworld.1.zwyhf6x4cpdm@    |
helloworld.1.jxxnqzximfy7@    | Hello from Docker!
helloworld.1.zwyhf6x4cpdm@    | Hello from Docker!
helloworld.1.jxxnqzximfy7@    | This message shows that your installation appears to be working correctly.
helloworld.1.zwyhf6x4cpdm@    | This message shows that your installation appears to be working correctly.
helloworld.1.zwyhf6x4cpdm@   |
helloworld.1.jxxnqzximfy7@    |
helloworld.1.jxxnqzximfy7@    | To generate this message, Docker took the following steps:
helloworld.1.zwyhf6x4cpdm@    | To generate this message, Docker took the following steps:
helloworld.1.zwyhf6x4cpdm@    |  1. The Docker client contacted the Docker daemon.
helloworld.1.jxxnqzximfy7@    |  1. The Docker client contacted the Docker daemon.
helloworld.1.jxxnqzximfy7@    |  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
helloworld.1.zwyhf6x4cpdm@    |  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
helloworld.1.zwyhf6x4cpdm@    |     (amd64)
helloworld.1.jxxnqzximfy7@    |     (amd64)
helloworld.1.zwyhf6x4cpdm@   |  3. The Docker daemon created a new container from that image which runs the
helloworld.1.jxxnqzximfy7@    |  3. The Docker daemon created a new container from that image which runs the
helloworld.1.jxxnqzximfy7@    |     executable that produces the output you are currently reading.
helloworld.1.zwyhf6x4cpdm@    |     executable that produces the output you are currently reading.
helloworld.1.zwyhf6x4cpdm@    |  4. The Docker daemon streamed that output to the Docker client, which sent it
helloworld.1.jxxnqzximfy7@    |  4. The Docker daemon streamed that output to the Docker client, which sent it
helloworld.1.jxxnqzximfy7@    |     to your terminal.
helloworld.1.zwyhf6x4cpdm@    |     to your terminal.
helloworld.1.jxxnqzximfy7@    |
helloworld.1.jxxnqzximfy7@    | To try something more ambitious, you can run an Ubuntu container with:
helloworld.1.zwyhf6x4cpdm@    |
helloworld.1.zwyhf6x4cpdm@    | To try something more ambitious, you can run an Ubuntu container with:
helloworld.1.jxxnqzximfy7@    |  $ docker run -it ubuntu bash
helloworld.1.jxxnqzximfy7@    |
helloworld.1.zwyhf6x4cpdm@    |  $ docker run -it ubuntu bash
helloworld.1.jxxnqzximfy7@    | Share images, automate workflows, and more with a free Docker ID:
helloworld.1.jxxnqzximfy7@    |  https://hub.docker.com/
helloworld.1.zwyhf6x4cpdm@    |
helloworld.1.zwyhf6x4cpdm@    | Share images, automate workflows, and more with a free Docker ID:
helloworld.1.jxxnqzximfy7@    |
helloworld.1.zwyhf6x4cpdm@    |  https://hub.docker.com/
helloworld.1.zwyhf6x4cpdm@    |
helloworld.1.jxxnqzximfy7@    | For more examples and ideas, visit:
helloworld.1.jxxnqzximfy7@    |  https://docs.docker.com/get-started/
helloworld.1.zwyhf6x4cpdm@    | For more examples and ideas, visit:
helloworld.1.jxxnqzximfy7@    |
helloworld.1.zwyhf6x4cpdm@    |  https://docs.docker.com/get-started/
helloworld.1.zwyhf6x4cpdm@    |
helloworld.1.yw17ktyymrp6@    |
helloworld.1.yw17ktyymrp6@    | Hello from Docker!
helloworld.1.yw17ktyymrp6@    | This message shows that your installation appears to be working correctly.

您应该尝试使用不同的 Docker 映像,例如 busybox

[~]$ docker service create --name helloworld busybox:latest sh -c "while true; do echo Hello; sleep 2; done"
yjxzteshp7k2xf4aznj4l86s6
Since --detach=false was not specified, tasks will be created in the background.
In a future release, --detach=false will become the default.
[~]$ docker service ps helloworld --no-trunc
ID                          NAME                IMAGE                                                                                    NODE                              DESIRED STATE       CURRENT STATE          ERROR               PORTS
33xe78ekfjkmti8yahrcp5gug   helloworld.1        busybox:latest@sha256:2a03a6059f21e150ae84b0973863609494aad70f0a80eaeb64bddd8d92465812      Running             Running 1 second ago
[~]$ docker service logs -f helloworld
helloworld.1.33xe78ekfjkm@    | Hello
helloworld.1.33xe78ekfjkm@    | Hello
helloworld.1.33xe78ekfjkm@    | Hello
helloworld.1.33xe78ekfjkm@    | Hello
helloworld.1.33xe78ekfjkm@    | Hello
^C

【讨论】:

  • 所以如果我想使用图片,那么在compose yml文件中我可以在命令参数中对/bin/bash,这样图片不会立即存在并运行吗?
  • 取决于 Docker 镜像。例如,hello-world 图像不包含 /bin/bash 二进制文件。下面是该图像的 Dockerfile:github.com/docker-library/hello-world/blob/… 这就是为什么我在示例中使用了busybox 图像。
  • 好的,得到你提到的东西,但为什么它会抛出错误作为检测到的任务失败? :/ 它应该立即运行并结束。
  • 默认情况下,当您创建一个 swarm 服务时,期望的状态是始终运行 1 个副本。因此,当您的容器完成执行时,服务会立即生成一个新服务。可以参考官方文档更好理解:docs.docker.com/engine/swarm/how-swarm-mode-works/services
  • 那么我可以使用 compose yml 文件来处理 version: '3' services: distcc-master: image: 192.168.1.12:5000/builddeps_essential-distcc-master command: /bin/bash distcc-worker: image: 192.168.1.12:5000/builddeps_essential-distcc-worker command: /bin/bash 吗,其中 image 是我的注册表中的图像并且可以访问
【解决方案2】:

检查 docker 日志可能是您能够找到的一些错误或问题。喜欢 -->

没有这样的文件或目录

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    • 2016-06-13
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多