创建docker服务时检测到某些图像的任务失败

创建docker服务时检测到某些图像的任务失败,docker,docker-swarm,docker-swarm-mode,Docker,Docker Swarm,Docker Swarm Mode,我正在尝试创建docker swarm服务,但我遇到了一些奇怪的行为: 对于某些图像,它是成功的,而对于某些图像,我得到一个错误: docker服务创建nginx 89t21k3udf007pvl2ucvmdp9l 总体进度:1项任务中的1项 1/1:正在运行[================================================================>] 验证:服务聚合成功 docker服务创建hello world 8Hhdki32YPFWSH2WVijk

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

对于某些图像,它是成功的,而对于某些图像,我得到一个错误:

docker服务创建nginx
89t21k3udf007pvl2ucvmdp9l
总体进度:1项任务中的1项
1/1:正在运行[================================================================>]
验证:服务聚合成功

docker服务创建hello world
8Hhdki32YPFWSH2WVijkMvb
总体进度:1项任务中有0项任务
1/1:准备[====================================================>]
验证:检测到任务失败
-->失败

仅供参考:
docker pull hello world
工作正常

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


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

它失败了,因为从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

您可以使用
docker服务检查hello world
docker服务ps hello world--no trunc
获取有关您的服务的更多详细信息。这应该可以帮助您诊断问题。您可以为hello world image创建服务吗?因此,如果我想使用映像,那么在compose yml文件中,我可以在命令参数中右键/bin/bash,以便映像不会立即存在并运行吗?这取决于Docker映像。例如,
helloworld
图像不包括
/bin/bash
二进制文件。下面是该图像的Dockerfile:这就是为什么我在示例中使用了
busybox
图像。好的,得到了您提到的内容,但为什么它会在检测到任务失败时抛出错误?:/它应该立即运行并结束。默认情况下,当您创建swarm服务时,所需的状态是始终运行1个副本。因此,当容器完成执行时,服务会立即生成一个新的容器。为了更好地理解,您可以参考官方文档:那么我可以使用compose yml文件来处理
版本:“3”服务:distcc master:image:192.168.1.12:5000/builddeps_essential-distcc-master命令:/bin/bash distcc-worker:image:192.168.1.12:5000/builddeps_essential-distcc-worker命令:/bin/bash
其中image是来自我的注册表的图像,可以访问