hashicorp / packer-plugin-docker

Packer plugin for Docker Builder
https://www.packer.io/docs/builders/docker
Mozilla Public License 2.0
31 stars 25 forks source link

simple docker build changing CMD and ENTRYPOINT of resulting image #132

Closed josh-m-sharpe closed 6 months ago

josh-m-sharpe commented 1 year ago

Community Note

Overview of the Issue

the resulting image packer produces is changing the CMD and Entrypoint (possibly other things)

build {
  name = "amzn2-ctm-core"

  source "source.docker.dockerhub" {
    image  = "amazonlinux:2"
  }

  post-processors {
    post-processor "docker-tag" {
      tags = [
        "core_${local.timestamp}",
        "core_latest"
      ]
    }
  }
}

After building this, comparing the images:

# The source image:
$ docker inspect amazonlinux:2 | jq -s ".[0][0].Config.Cmd"
[
  "/bin/bash"
]
$ docker inspect amazonlinux:2 | jq -s ".[0][0].Config.Entrypoint"
null

# the resulting image
$ docker inspect acct1234.dkr.ecr.us-east-1.amazonaws.com/amzn2-ctm:core_20221118194409 | jq -s ".[0][0].Config.Cmd"
null
$ docker inspect acct1234.dkr.ecr.us-east-1.amazonaws.com/amzn2-ctm:core_20221118194409 | jq -s ".[0][0].Config.Entrypoint"
[
  "/bin/sh"
]

Why is packer doing this?

Packer version

1.8.4

Operating system and Environment details

built on, and sourcing from: amazonlinux;2

josh-m-sharpe commented 1 year ago

Here's another similar example:

build {
  name = "amzn2-ctm-core"

  source "source.docker.dockerhub" {
    image  = "amazonlinux:2"
    changes = [
      "ENTRYPOINT [\"/bin/bash\", \"-l\", \"-c\"]",
      "CMD /bin/bash"
    ]
  }

  post-processors {
    post-processor "docker-tag" {
      tags = [
        "core_${local.timestamp}",
        "core_latest"
      ]
    }
  }
}

Results in docker inspect with this:

            "Cmd": [
                "/bin/sh",
                "-c",
                "/bin/bash"
            ],
            "Entrypoint": [
                "/bin/bash",
                "-l",
                "-c"
            ],

This is very unexpected.

huyz commented 1 year ago

Yes this breaks Dockerfile images with esoteric errors.