ansible - 使用 ansible 构建时在 Dockerfile 中设置相对路径
问题描述
我正在尝试使用 ansible 构建一些 docker 文件,但不清楚用作构建目录的内容。
目录结构
- build_images.yml
- 部署
- app_files/requirements.txt
- 码头文件
- 应用程序/Dockerfile
我正在运行他的 build_images.yml 文件,如下所示(它选择了正确的路径)
build_images.yml 文件
---
- hosts: localhost
connection: local
tasks:
- name: Build container
docker_image:
name: app
path: deploy/dockerfiles/app
pull: no
state: build
但是,我的 Dockerfile 包含
FROM base_image:latest
COPY ./deploy/app_files/requirements.txt requirements.txt
我已经尝试了该目录的一些变体,但它不断返回“没有这样的文件或目录”
用于 Dockerfile 中的相对路径的适当的基本 docker 构建目录是什么?
解决方案
路径:与状态“存在”一起使用来构建图像。将是包含用于构建映像的上下文和 Dockerfile 的目录的路径。
dockerfile - 在 2.0 中添加:与 state present 一起使用,为构建映像时使用的 Dockerfile 提供备用名称。
然后我会尝试
- name: Build container
docker_image:
name: app
path: deploy
dockerfile: dockerfiles/app/Dockerfile
pull: no
state: build
在你的 Dockerfile 中:
FROM base_image:latest
COPY app_files/requirements.txt requirements.txt
请注意,您的原始路径无论如何都是错误的(指向dockerfiles
而不是app_files
)。
推荐阅读
- java - 创建名称为“studentController”的 bean 时出错:通过字段“studentDao”表达的依赖关系不满足
- php - 如何将 entity_manager 从控制器传递到表单类作为选项?错误:缺少必需的选项“entity_manager”
- hardware - 无法将 Monster motor shield 与 Beaglebone black 连接
- css - 如何在整个内容结束后显示页脚?
- ibm-cloud - 我可以使用 IBM Speech-to-Text 中的“word_confidence”进行发音学习吗?
- linux - 独立于平台的 Makefile - Windows 和 WSL
- c# - 从文件中读取行并写入多个 PDF 不起作用
- java - 正在寻找用于解密使用 openssl -aes-256-cbc -a -salt 命令加密的消息的 Java 实现?
- python - 将值添加到python中的嵌套字典
- java - 如何将一个类连接到另一个类以用于在线购物系统?