docs: add an example to build an image with docker_image (#158)

* docs: add an example to build a Docker image with docker_image
* docs: add description of the docker_image.build block
This commit is contained in:
Shunsuke Suzuki 2021-03-29 17:09:08 +09:00 committed by GitHub
parent 6b0f977735
commit 3f9193463f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,6 +26,25 @@ resource "docker_image" "ubuntu" {
``` ```
Building a Docker image
```hcl
# 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 ### Dynamic image
```hcl ```hcl
@ -57,19 +76,22 @@ The following arguments are supported:
<a id="build-1"></a> <a id="build-1"></a>
### Build ### Build
Build image. Build image.
Please see [docker build command reference](https://docs.docker.com/engine/reference/commandline/build/#options) too.
The `build` block supports: The `build` block supports:
* `path` - (Required, string) * `path` - (Required, string) Context path
* `dockerfile` - (Optional, string) default Dockerfile * `dockerfile` - (Optional, string, default `Dockerfile`) Path to the Dockerfile
* `tag` - (Optional, list of strings) * `tag` - (Optional, list of strings) Built Docker image name and optionally a tag in the `name:tag` format
* `force_remove` - (Optional, boolean) * `force_remove` - (Optional, boolean) Always remove intermediate containers
* `remove` - (Optional, boolean) default true * `remove` - (Optional, boolean, default `true`) Remove intermediate containers after a successful build
* `no_cache` - (Optional, boolean) * `no_cache` - (Optional, boolean) Do not use cache when building the image
* `target` - (Optional, string) * `target` - (Optional, string) Set the target build stage to build
* `build_arg` - (Optional, map of strings) * `build_arg` - (Optional, map of strings) Set build-time variables
* `label` - (Optional, map of strings) * `label` - (Optional, map of strings) Set metadata for an image
## Attributes Reference ## Attributes Reference