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

Packer docker builder reseting ENTRYPOINT and CMD #158

Closed hc-github-team-packer closed 6 months ago

hc-github-team-packer commented 11 months ago

This issue was originally opened by @saulfm08 in https://github.com/hashicorp/packer/issues/12529 and has been migrated to this repository. The original issue description is below.


We are using packer to build a container with a parent that includes an entrypoint. In the packer build we "reset" entrypoint with ENTRYPOINT []. Unfortunately the container is being committed with the entrypoint of the parent still in place.

Doing this in a Dockerfile gets rid of the entrypoint from parent:

FROM ep-issue:parent
ENTRYPOINT []
CMD []

While the same in packer version does not:

source "docker" "wordpress" {
  image  = "wordpress:latest"
  commit = true
}

build {
  name = "my-wp"
  sources = [
    "source.docker.wordpress"
  ]

  post-processors {
    post-processor "docker-tag" {
      repository = "${var.docker_registry}/${var.docker_repository}"
      tags       = ["latest"]
    }
    post-processor "docker-push" {
      ecr_login      = true
      login_server   = var.docker_registry
    }
  }
}
docker image inspect wordpress:latest -f '{{ .ContainerConfig.Cmd }}'
[/bin/sh -c #(nop)  CMD ["apache2-foreground"]]

docker image inspect my-wp:latest -f '{{ .ContainerConfig.Cmd }}'
[]

docker image inspect wordpress:latest -f '{{ .ContainerConfig.Entrypoint }}'
[docker-entrypoint.sh]

docker image inspect my-wp:latest -f '{{ .ContainerConfig.Entrypoint }}'
[/bin/sh]

Packer version 1.9.2 Host platform MacOS Ventura

Gist of packer-entrypoint-build.log Gist of the simple script to reproduce the bug