简体   繁体   English

使用 Ansible Playbook 构建 Docker 镜像(使用多目标 Dockerfile)

[英]Build Docker image using Ansible Playbook (with multi-target Dockerfile)

Is there any option how to implement Docker command ( --target parameter)是否有任何选项如何实现 Docker 命令( --target参数)

docker build --target backend -t project/backend:latest

in Ansible Playbook with docker_image module?在带有docker_image模块的 Ansible Playbook 中? Right now in playbook:现在在剧本中:

- hosts: localhost
  tasks:
    - name: Build backend image
      docker_image:
        path: /var/lib/workspace/project/backend
        name: project/backend:latest

This worked for me.这对我有用。

---
- name: Copy Dockerfile
  copy: src=Dockerfile dest=/tmp/path/
- name: Build osquery image
    docker_image:
      path: /tmp/path/
      name: imagename
      tag: v1

In the current version of Ansible it is possible to define the target in docker_image .在当前版本的 Ansible 中,可以在docker_image定义目标。

Ansible Documentation - community.docker.docker_image Ansible 文档 - community.docker.docker_image

I think this should work for you我认为这应该适合你

- hosts: localhost
  tasks:
    - name: Build backend image
      docker_image:
        path: /var/lib/workspace/project/backend
        name: project/backend:latest
        target: backend

When the Dockerfile is something like当 Dockerfile 类似于

FROM for-example-php-image AS baseimage 
# Common things

FROM baseimage AS backend
# Things needed only in backend

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM