diff --git a/website/pages/docs/builders/docker.mdx b/website/pages/docs/builders/docker.mdx
index bc0cae85c..2c33dff3b 100644
--- a/website/pages/docs/builders/docker.mdx
+++ b/website/pages/docs/builders/docker.mdx
@@ -39,6 +39,9 @@ documentation.
Below is a fully functioning example. It doesn't do anything useful, since no
provisioners are defined, but it will effectively repackage an image.
+
+
+
```json
{
"type": "docker",
@@ -47,12 +50,32 @@ provisioners are defined, but it will effectively repackage an image.
}
```
+
+
+
+```hcl
+source "docker" "example" {
+ image = "ubuntu"
+ export_path = "image.tar"
+}
+
+build {
+ sources = ["source.docker.example"]
+}
+```
+
+
+
+
## Basic Example: Commit
Below is another example, the same as above but instead of exporting the
running container, this one commits the container to an image. The image can
then be more easily tagged, pushed, etc.
+
+
+
```json
{
"type": "docker",
@@ -61,6 +84,23 @@ then be more easily tagged, pushed, etc.
}
```
+
+
+
+```hcl
+source "docker" "example" {
+ image = "ubuntu"
+ commit = true
+}
+
+build {
+ sources = ["source.docker.example"]
+}
+```
+
+
+
+
## Basic Example: Changes to Metadata
Below is an example using the changes argument of the builder. This feature
@@ -72,6 +112,9 @@ Docker](https://docs.docker.com/engine/reference/commandline/commit/).
Example uses of all of the options, assuming one is building an NGINX image
from ubuntu as an simple example:
+
+
+
```json
{
"type": "docker",
@@ -91,6 +134,30 @@ from ubuntu as an simple example:
}
```
+
+
+
+```hcl
+source "docker" "example" {
+ image = "ubuntu"
+ commit = true
+ changes = [
+ "USER www-data",
+ "WORKDIR /var/www",
+ "ENV HOSTNAME www.example.com",
+ "VOLUME /test1 /test2",
+ "EXPOSE 80 443",
+ "LABEL version=1.0",
+ "ONBUILD RUN date",
+ "CMD [\"nginx\", \"-g\", \"daemon off;\"]",
+ "ENTRYPOINT /var/www/start.sh"
+ ]
+}
+```
+
+
+
+
Allowed metadata fields that can be changed are:
- CMD
@@ -164,21 +231,43 @@ created image. This is accomplished using a sequence definition (a collection
of post-processors that are treated as as single pipeline, see
[Post-Processors](/docs/templates/post-processors) for more information):
+
+
+
```json
{
"post-processors": [
[
{
"type": "docker-import",
- "repository": "hashicorp/packer",
+ "repository": "myrepo/myimage",
"tag": "0.7"
},
- "docker-push"
+ {
+ "type": "docker-push"
+ }
]
]
}
```
+
+
+
+```hcl
+ post-processors {
+ post-processor "docker-import" {
+ repository = "myrepo/myimage"
+ tag = "0.7"
+ }
+ post-processor "docker-push" {}
+ }
+}
+```
+
+
+
+
In the above example, the result of each builder is passed through the defined
sequence of post-processors starting first with the `docker-import`
post-processor which will import the artifact as a docker image. The resulting
@@ -204,21 +293,43 @@ definition (a collection of post-processors that are treated as as single
pipeline, see [Post-Processors](/docs/templates/post-processors) for more
information):
+
+
+
```json
{
"post-processors": [
[
{
"type": "docker-tag",
- "repository": "hashicorp/packer",
+ "repository": "myrepo/myimage",
"tag": "0.7"
},
- "docker-push"
+ {
+ "type": "docker-push"
+ }
]
]
}
```
+
+
+
+```hcl
+ post-processors {
+ post-processor "docker-tag" {
+ repository = "myrepo/myimage"
+ tag = "0.7"
+ }
+ post-processor "docker-push" {}
+ }
+}
+```
+
+
+
+
In the above example, the result of each builder is passed through the defined
sequence of post-processors starting first with the `docker-tag` post-processor
which tags the committed image with the supplied repository and tag
@@ -230,13 +341,16 @@ Going a step further, if you wanted to tag and push an image to multiple
container repositories, this could be accomplished by defining two,
nearly-identical sequence definitions, as demonstrated by the example below:
+
+
+
```json
{
"post-processors": [
[
{
"type": "docker-tag",
- "repository": "hashicorp/packer1",
+ "repository": "myrepo/myimage1",
"tag": "0.7"
},
"docker-push"
@@ -244,7 +358,7 @@ nearly-identical sequence definitions, as demonstrated by the example below:
[
{
"type": "docker-tag",
- "repository": "hashicorp/packer2",
+ "repository": "myrepo/myimage2",
"tag": "0.7"
},
"docker-push"
@@ -253,6 +367,30 @@ nearly-identical sequence definitions, as demonstrated by the example below:
}
```
+
+
+
+```hcl
+ post-processors {
+ post-processor "docker-tag" {
+ repository = "myrepo/myimage1"
+ tag = "0.7"
+ }
+ post-processor "docker-push" {}
+ }
+ post-processors {
+ post-processor "docker-tag" {
+ repository = "myrepo/myimage2"
+ tag = "0.7"
+ }
+ post-processor "docker-push" {}
+ }
+}
+```
+
+
+
+
## Docker For Windows
@@ -268,6 +406,9 @@ containers, so you must either commit or discard them.
The following is a fully functional template for building a Windows
container.
+
+
+
```json
{
"builders": [
@@ -282,12 +423,34 @@ container.
}
```
+
+
+
+```hcl
+source "docker" "windows" {
+ image = "ubuntu"
+ container_dir = "c:/app"
+ windows_container = true
+ commit = true
+}
+
+build {
+ sources = ["source.docker.example"]
+}
+```
+
+
+
+
## Amazon EC2 Container Registry
Packer can tag and push images for use in [Amazon EC2 Container
Registry](https://aws.amazon.com/ecr/). The post processors work as described
above and example configuration properties are shown below:
+
+
+
```json
{
"post-processors": [
@@ -309,6 +472,27 @@ above and example configuration properties are shown below:
}
```
+
+
+
+```hcl
+post-processors {
+ post-processor "docker-tag" {
+ repository = "12345.dkr.ecr.us-east-1.amazonaws.com/packer"
+ tag = "0.7"
+ }
+ post-processor "docker-push" {
+ ecr_login = true
+ aws_access_key = "YOUR KEY HERE"
+ aws_secret_key = "YOUR SECRET KEY HERE"
+ login_server = "https://12345.dkr.ecr.us-east-1.amazonaws.com/"
+ }
+}
+```
+
+
+
+
[Learn how to set Amazon AWS
credentials.](/docs/builders/amazon#specifying-amazon-credentials)