community.docker.docker_image_build (3.8.1) — module

Build Docker images using Docker buildx

| "added in version" 3.6.0 of community.docker"

Authors: Felix Fontein (@felixfontein)

Install collection

Install with ansible-galaxy collection install community.docker:==3.8.1


Add to requirements.yml

  collections:
    - name: community.docker
      version: 3.8.1

Description

This module allows you to build Docker images using Docker's buildx plugin (BuildKit).


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Build Python 3.12 image
  community.docker.docker_image_build:
    name: localhost/python/3.12:latest
    path: /home/user/images/python
    dockerfile: Dockerfile-3.12

Inputs

    
tag:
    default: latest
    description:
    - Tag for the image name O(name) that is to be tagged.
    - If O(name)'s format is C(name:tag), then the tag value from O(name) will take precedence.
    type: str

tls:
    default: false
    description:
    - Secure the connection to the API by using TLS without verifying the authenticity
      of the Docker host server. Note that if O(validate_certs) is set to V(true) as well,
      it will take precedence.
    - If the value is not specified in the task, the value of environment variable E(DOCKER_TLS)
      will be used instead. If the environment variable is not set, the default value
      will be used.
    type: bool

args:
    description:
    - Provide a dictionary of C(key:value) build arguments that map to Dockerfile ARG
      directive.
    - Docker expects the value to be a string. For convenience any non-string values will
      be converted to strings.
    type: dict

name:
    description:
    - 'Image name. Name format will be one of: C(name), C(repository/name), C(registry_server:port/name).
      When pushing or pulling an image the name can optionally include the tag by appending
      C(:tag_name).'
    - Note that image IDs (hashes) and names with digest cannot be used.
    required: true
    type: str

path:
    description:
    - The path for the build environment.
    required: true
    type: path

pull:
    default: false
    description:
    - When building an image downloads any updates to the FROM image in Dockerfile.
    type: bool

labels:
    description:
    - Dictionary of key value pairs.
    type: dict

target:
    description:
    - When building an image specifies an intermediate build stage by name as a final
      stage for the resulting image.
    type: str

ca_path:
    aliases:
    - ca_cert
    - tls_ca_cert
    - cacert_path
    description:
    - Use a CA certificate when performing server verification by providing the path to
      a CA certificate file.
    - If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH)
      is set, the file C(ca.pem) from the directory specified in the environment variable
      E(DOCKER_CERT_PATH) will be used.
    type: path

network:
    description:
    - The network to use for C(RUN) build instructions.
    type: str

nocache:
    default: false
    description:
    - Do not use cache when building an image.
    type: bool

rebuild:
    choices:
    - never
    - always
    default: never
    description:
    - Defines the behavior of the module if the image to build (as specified in O(name)
      and O(tag)) already exists.
    type: str

platform:
    description:
    - Platform in the format C(os[/arch[/variant]]).
    type: str

shm_size:
    description:
    - Size of C(/dev/shm) in format C(<number>[<unit>]). Number is positive integer. Unit
      can be V(B) (byte), V(K) (kibibyte, 1024B), V(M) (mebibyte), V(G) (gibibyte), V(T)
      (tebibyte), or V(P) (pebibyte).
    - Omitting the unit defaults to bytes. If you omit the size entirely, Docker daemon
      uses V(64M).
    type: str

etc_hosts:
    description:
    - Extra hosts to add to C(/etc/hosts) in building containers, as a mapping of hostname
      to IP address.
    type: dict

cache_from:
    description:
    - List of image names to consider as cache source.
    elements: str
    type: list

client_key:
    aliases:
    - tls_client_key
    - key_path
    description:
    - Path to the client's TLS key file.
    - If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH)
      is set, the file C(key.pem) from the directory specified in the environment variable
      E(DOCKER_CERT_PATH) will be used.
    type: path

docker_cli:
    description:
    - Path to the Docker CLI. If not provided, will search for Docker CLI on the E(PATH).
    type: path

dockerfile:
    description:
    - Provide an alternate name for the Dockerfile to use when building an image.
    - This can also include a relative path (relative to O(path)).
    type: str

api_version:
    aliases:
    - docker_api_version
    default: auto
    description:
    - The version of the Docker API running on the Docker Host.
    - Defaults to the latest version of the API supported by this collection and the docker
      daemon.
    - If the value is not specified in the task, the value of environment variable E(DOCKER_API_VERSION)
      will be used instead. If the environment variable is not set, the default value
      will be used.
    type: str

cli_context:
    description:
    - The Docker CLI context to use.
    type: str

client_cert:
    aliases:
    - tls_client_cert
    - cert_path
    description:
    - Path to the client's TLS certificate file.
    - If the value is not specified in the task and the environment variable E(DOCKER_CERT_PATH)
      is set, the file C(cert.pem) from the directory specified in the environment variable
      E(DOCKER_CERT_PATH) will be used.
    type: path

docker_host:
    aliases:
    - docker_url
    default: unix:///var/run/docker.sock
    description:
    - The URL or Unix socket path used to connect to the Docker API. To connect to a remote
      host, provide the TCP connection string. For example, V(tcp://192.0.2.23:2376).
      If TLS is used to encrypt the connection, the module will automatically replace
      C(tcp) in the connection URL with C(https).
    - If the value is not specified in the task, the value of environment variable E(DOCKER_HOST)
      will be used instead. If the environment variable is not set, the default value
      will be used.
    type: str

tls_hostname:
    description:
    - When verifying the authenticity of the Docker Host server, provide the expected
      name of the server.
    - If the value is not specified in the task, the value of environment variable E(DOCKER_TLS_HOSTNAME)
      will be used instead. If the environment variable is not set, the default value
      will be used.
    type: str

validate_certs:
    aliases:
    - tls_verify
    default: false
    description:
    - Secure the connection to the API by using TLS and verifying the authenticity of
      the Docker host server.
    - If the value is not specified in the task, the value of environment variable E(DOCKER_TLS_VERIFY)
      will be used instead. If the environment variable is not set, the default value
      will be used.
    type: bool

Outputs

image:
  description: Image inspection results for the affected image.
  returned: success
  sample: {}
  type: dict

See also