我正在使用这个 Ansible 模块community.docker.docker_image
构建 docker 镜像。我想用--secret
标志,因此我需要启用 BuildKit。
我确实编辑了/etc/docker/daemon.json
文件并添加了这一行"features": { "buildkit": true }
然后重新启动docker服务。
但是Ansible运行时仍然报错;
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error building local:5000/test - code: None, message: the --mount option requires BuildKit. Refer to https://docs.docker.com/go/buildkit/ to learn how to build images with BuildKit enabled ...
可靠的任务:
- name: Build an image and push it to a private repo
community.docker.docker_image:
build:
path: "{{ role_path }}/files/test"
args:
secret: 'id=test_app_secret_id,src={{ tempfile_1.path }}'
name: local:5000/test
tag: v1.1.2
push: yes
force_tag: yes
source: build
在 Dockerfile 中,我使用的秘密如下:
RUN --mount=type=secret,id=test_app_secret_id
关于如何解决这个问题有什么想法吗?
Ansible 不支持使用 buildkit 进行构建(截至 2023 年 11 月 21 日...)community.docker.docker_image
模块。引用文档中的注释 https://docs.ansible.com/ansible/latest/collections/community/docker/docker_image_module.html#notes
构建镜像是使用 Docker 守护进程的 API 完成的。不可能以这种方式使用 BuildKit / buildx。
所以暂时的解决方案是通过 shell 设置正确的环境。就像是:
- name: Build an image with BuildKit and push it to a private repo
vars:
image: local:5000/test
tag: v1.1.2
ansible.builtin.shell:
cmd: |-
docker build --secret "id=test_app_secret_id,src={{ tempfile_1.path }}" -t {{ image }}:{{ tag }} .
docker push {{ image }}:{{ tag }}
chdir: "{{ role_path }}/files/test"
environment:
DOCKER_BUILDKIT: 1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)