mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2026-01-01 04:19:36 -05:00
* docs: add an example to build a Docker image with docker_image * docs: add description of the docker_image.build block
3.1 KiB
3.1 KiB
| layout | page_title | sidebar_current | description |
|---|---|---|---|
| docker | Docker: docker_image | docs-docker-resource-image | Pulls a Docker image to a given Docker host. |
docker_image
Pulls a Docker image to a given Docker host from a Docker Registry.
This resource will not pull new layers of the image automatically unless used in
conjunction with docker_registry_image
data source to update the pull_triggers field.
Example Usage
# Find the latest Ubuntu precise image.
resource "docker_image" "ubuntu" {
name = "ubuntu:precise"
}
# Access it somewhere else with ${docker_image.ubuntu.latest}
Building a Docker image
# image "zoo" and "zoo:develop" are built
resource "docker_image" "zoo" {
name = "zoo"
build {
path = "."
tag = ["zoo:develop"]
build_arg = {
foo : "zoo"
}
label = {
author : "zoo"
}
}
}
Dynamic image
data "docker_registry_image" "ubuntu" {
name = "ubuntu:precise"
}
resource "docker_image" "ubuntu" {
name = data.docker_registry_image.ubuntu.name
pull_triggers = [data.docker_registry_image.ubuntu.sha256_digest]
}
Argument Reference
The following arguments are supported:
name- (Required, string) The name of the Docker image, including any tags or SHA256 repo digests.keep_locally- (Optional, boolean) If true, then the Docker image won't be deleted on destroy operation. If this is false, it will delete the image from the docker local storage on destroy operation.pull_triggers- (Optional, list of strings) List of values which cause an image pull when changed. This is used to store the image digest from the registry when using thedocker_registry_imagedata source to trigger an image update.pull_trigger- Deprecated, usepull_triggersinstead.force_remove- (Optional, boolean) If true, then the image is removed forcibly when the resource is destroyed.build- (Optional, block) See Build below for details.
Build
Build image.
Please see docker build command reference too.
The build block supports:
path- (Required, string) Context pathdockerfile- (Optional, string, defaultDockerfile) Path to the Dockerfiletag- (Optional, list of strings) Built Docker image name and optionally a tag in thename:tagformatforce_remove- (Optional, boolean) Always remove intermediate containersremove- (Optional, boolean, defaulttrue) Remove intermediate containers after a successful buildno_cache- (Optional, boolean) Do not use cache when building the imagetarget- (Optional, string) Set the target build stage to buildbuild_arg- (Optional, map of strings) Set build-time variableslabel- (Optional, map of strings) Set metadata for an image
Attributes Reference
The following attributes are exported in addition to the above configuration:
latest(string) - The ID of the image.