将 docker 个图像旋转到多个容器中
Spinning docker image into multiple containers
我正在使用 docker 为 LAMP 应用程序构建自动化 CI/CD 管道。
我希望将图像旋转到 5 个容器中,以便 5 个不同的开发人员可以处理他们的代码。这可以实现吗?我用副本试过了,但没成功。
version: '3'
services:
web:
build: .
ports:
- "8080:80"#
deploy:
mode: replicated
replicas: 4
我得到的错误:
:#!/bin/bash -eo pipefail docker-compose up ERROR: The Compose file
'./docker-compose.yml' is invalid because: Additional properties are
not allowed ('jobs' was unexpected) You might be seeing this error
because you're using the wrong Compose file version. Either specify a
supported version (e.g "2.2" or "3.3") and place your service
definitions under the services key, or omit the version key and place
your service definitions at the root of the file to use version 1. For
more on the Compose file format versions, see
docs.docker.com/compose/compose-file Exited with code 1 –
此外,开发人员可以从不同的容器推送、拉取和提交 git 吗?如果重建图像或 运行?
,在一个容器中完成的工作是否会丢失
构建此管道时我应该注意哪些事项。
首先,使用带有 docker build -t <image name>:<version/tag> .
的 Dockerfile
单独构建您的映像,然后使用带有 docker stack deploy
的以下合成文件来部署您的堆栈。
version: '3'
services:
web:
image: <image name>:<version/tag>
ports:
- "8080:80"#
deploy:
mode: replicated
replicas: 4
deploy
属性应该在服务内部,因为它描述了服务必须具有的副本数。它不是像 services
这样的全局属性。这似乎是您的撰写文件中的唯一问题,并且 docker compose up
在从管道中 运行ning 时抱怨这个问题。
更新
您不能使用单个 docker-compose
命令 运行 多个副本。要从 compose.yml
中 运行 多个副本,请在您的计算机上执行 docker swarm init
创建一个 swarm。
之后,只需将 docker-compose up
替换为 docker stack deploy <stack name>
。 docker-compose
简单地忽略 deploy
属性。
docker-compose up
和docker stack deploy <stack name>
的区别详见这篇文章:https://nickjanetakis.com/blog/docker-tip-23-docker-compose-vs-docker-stack
我正在使用 docker 为 LAMP 应用程序构建自动化 CI/CD 管道。
我希望将图像旋转到 5 个容器中,以便 5 个不同的开发人员可以处理他们的代码。这可以实现吗?我用副本试过了,但没成功。
version: '3'
services:
web:
build: .
ports:
- "8080:80"#
deploy:
mode: replicated
replicas: 4
我得到的错误:
:#!/bin/bash -eo pipefail docker-compose up ERROR: The Compose file './docker-compose.yml' is invalid because: Additional properties are not allowed ('jobs' was unexpected) You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the services key, or omit the version key and place your service definitions at the root of the file to use version 1. For more on the Compose file format versions, see docs.docker.com/compose/compose-file Exited with code 1 –
此外,开发人员可以从不同的容器推送、拉取和提交 git 吗?如果重建图像或 运行?
,在一个容器中完成的工作是否会丢失构建此管道时我应该注意哪些事项。
首先,使用带有 docker build -t <image name>:<version/tag> .
的 Dockerfile
单独构建您的映像,然后使用带有 docker stack deploy
的以下合成文件来部署您的堆栈。
version: '3'
services:
web:
image: <image name>:<version/tag>
ports:
- "8080:80"#
deploy:
mode: replicated
replicas: 4
deploy
属性应该在服务内部,因为它描述了服务必须具有的副本数。它不是像 services
这样的全局属性。这似乎是您的撰写文件中的唯一问题,并且 docker compose up
在从管道中 运行ning 时抱怨这个问题。
更新
您不能使用单个 docker-compose
命令 运行 多个副本。要从 compose.yml
中 运行 多个副本,请在您的计算机上执行 docker swarm init
创建一个 swarm。
之后,只需将 docker-compose up
替换为 docker stack deploy <stack name>
。 docker-compose
简单地忽略 deploy
属性。
docker-compose up
和docker stack deploy <stack name>
的区别详见这篇文章:https://nickjanetakis.com/blog/docker-tip-23-docker-compose-vs-docker-stack