Docker swarm:在堆栈部署期间忽略docker中的“ build”配置撰写文件 [英] Docker swarm: 'build' configuration in docker compose file ignored during stack deployment
问题描述
我们创建了具有多个服务的docker compose文件。这些服务的图像是在运行时使用构建配置选项构建的。相应的Dockerfile在相应的目录中给出。
We have created a docker compose file with multiple services. The images for these services are built in runtime using 'build' configuration option. The corresponding Dockerfile(s) are given in the respective directories.
示例Docker编写文件...
Sample docker compose file...
version: '3'
services:
db2server:
build: ./db2server
ports:
- "50005:50000"
command: ["db2start"]
appruntime:
build: ./appruntime
depends_on:
- db2server
此docker compose文件与 docker-compose
命令一起使用。
This docker compose file works with docker-compose
command.
- 映像是在运行时根据
db2server
&appruntime
目录 - 这些映像已部署在主机中
- The images are built in runtime from the Dockerfile(s) present in
db2server
&appruntime
directories - These images get deployed in the host machine
但是当我们尝试将其部署在Docker群中时,会引发以下错误...
But when we try to deploy this in a docker swarm, the following error is thrown...
docker堆栈部署-c /home/docker/docker-compose.yml应用程序
docker stack deploy -c /home/docker/docker-compose.yml app
Ignoring unsupported options: build
Creating network app_default
Creating service app_db2server
failed to create service app_db2server: Error response from daemon: rpc error: code = InvalidArgument desc = ContainerSpec: image reference must be provided
在docker swarm中的堆栈部署过程中,似乎忽略了 build配置选项。
Looks like the 'build' configuration option is ignored during stack deployment in docker swarm.
我们如何部署在docker swarm中的docker compose文件中定义的这些服务(带有构建选项)。
How can we deploy these services (with build option) defined in docker compose file in a docker swarm.
推荐答案
如果有人还在,您可以通过设置图像参数和构建参数,如您在 docs 的构建部分中所见一个>。因此文件应如下所示:
If anyone is still on this you can tag the built image in compose by setting the image parameter along with the build parameter, as you can see in the build section of the docs. So the file should look like:
version: '3'
services:
db2server:
image: <your registry here>/db2server
build: ./db2server
ports:
- "50005:50000"
command: ["db2start"]
appruntime:
image: <your registry here>/appruntime
build: ./appruntime
depends_on:
- db2server
然后您可以执行以下操作:
then you can do:
docker-compose build
docker-compose push
docker stack deploy -c /home/docker/docker-compose.yml app
这篇关于Docker swarm:在堆栈部署期间忽略docker中的“ build”配置撰写文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!