Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .web-docs/components/builder/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,12 @@ You must specify (only) one of `commit`, `discard`, or `export_path`.
- `volumes` (map[string]string) - A mapping of additional volumes to mount into this container. The key of
the object is the host path, the value is the container path.

- `fix_upload_owner` (bool) - If true, files uploaded to the container will be owned by the user the
container is running as. If false, the owner will depend on the version
of docker installed in the system. Defaults to true.
- `fix_upload_owner` (bool) - If true, files uploaded to the container (for example shell provisioner
scripts) will be owned by the user the container is running as. If false,
uploaded files keep the ownership Docker assigns on copy (often root),
which can cause "Permission denied" when the container USER is non-root.
Defaults to true. Set explicitly to false only if you need Docker's
default copy ownership behavior.

- `windows_container` (bool) - If "true", tells Packer that you are building a Windows container
running on a windows host. This is necessary for building Windows
Expand Down
23 changes: 18 additions & 5 deletions builder/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ type Config struct {
// A mapping of additional volumes to mount into this container. The key of
// the object is the host path, the value is the container path.
Volumes map[string]string `mapstructure:"volumes" required:"false"`
// If true, files uploaded to the container will be owned by the user the
// container is running as. If false, the owner will depend on the version
// of docker installed in the system. Defaults to true.
// If true, files uploaded to the container (for example shell provisioner
// scripts) will be owned by the user the container is running as. If false,
// uploaded files keep the ownership Docker assigns on copy (often root),
// which can cause "Permission denied" when the container USER is non-root.
// Defaults to true. Set explicitly to false only if you need Docker's
// default copy ownership behavior.
FixUploadOwner bool `mapstructure:"fix_upload_owner" required:"false"`
// If "true", tells Packer that you are building a Windows container
// running on a windows host. This is necessary for building Windows
Expand Down Expand Up @@ -165,8 +168,6 @@ type Config struct {

func (c *Config) Prepare(raws ...interface{}) ([]string, error) {

c.FixUploadOwner = true

var md mapstructure.Metadata
err := config.Decode(c, &config.DecodeOpts{
Metadata: &md,
Expand All @@ -183,6 +184,18 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
return nil, err
}

// Default FixUploadOwner if it wasn't set (bool zero-value is false).
hasFixUploadOwner := false
for _, k := range md.Keys {
if k == "fix_upload_owner" {
hasFixUploadOwner = true
break
}
}
if !hasFixUploadOwner {
c.FixUploadOwner = true
}

// Defaults
if len(c.RunCommand) == 0 {
c.RunCommand = []string{"-d", "-i", "-t", "--entrypoint=/bin/sh", "--", "{{.Image}}"}
Expand Down
9 changes: 6 additions & 3 deletions docs-partials/builder/docker/Config-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@
- `volumes` (map[string]string) - A mapping of additional volumes to mount into this container. The key of
the object is the host path, the value is the container path.

- `fix_upload_owner` (bool) - If true, files uploaded to the container will be owned by the user the
container is running as. If false, the owner will depend on the version
of docker installed in the system. Defaults to true.
- `fix_upload_owner` (bool) - If true, files uploaded to the container (for example shell provisioner
scripts) will be owned by the user the container is running as. If false,
uploaded files keep the ownership Docker assigns on copy (often root),
which can cause "Permission denied" when the container USER is non-root.
Defaults to true. Set explicitly to false only if you need Docker's
default copy ownership behavior.

- `windows_container` (bool) - If "true", tells Packer that you are building a Windows container
running on a windows host. This is necessary for building Windows
Expand Down