Packer: CMD not running after ENTRYPOINT

Created on 22 May 2017  路  7Comments  路  Source: hashicorp/packer

I have a docker file which uses ENTRYPOINT into a CMD. The entry point ends with :

exec "$@"

with the CMD being CMD node myapp.js.

This works fine when using regular dockerfiles but when built using packer it runs the entrypoint but not the CMD. No errors, packer builds just fine and the container runs fine except for the part where it doesn't execute the CMD statement.

Packer 1.0.0 on CENTOS 7

buildedocker question

Most helpful comment

Bumped into the same problem and here's what I found:
The thing here is how docker commit works - it applies the entrypoint and command of the container currently running. And if you see how packer runs the images by default (https://www.packer.io/docs/builders/docker.html#run_command), the command is indeed /bin/bash, which gets saved into the image.
Setting "run_command": ["-d", "{{.Image}}"] in the template saved my day in the end.

That said, at least a note in the docs could be really useful, given how the default behaviour is misleading.

All 7 comments

packer doesn't use dockerfiles. Can you post your packer.json?

Have more or less same problem it seems packer override CMD of the base image to /bin/bash

I've confirmed I'm having the same problem. Here's a very simply repro

{
  "builders": [
    {
      "type": "docker",
      "image": "python:3.6",
      "commit": true
    }
  ],
  "post-processors": [
    [
      {
        "type": "docker-tag",
        "repository": "python-no-cmd-test",
        "tag": "latest"
      }
    ]
  ]
}
$ packer build test.json
docker output will be in this color.

==> docker: Creating a temporary directory for sharing data...
==> docker: Pulling Docker image: python:3.6
    docker: 3.6: Pulling from library/python
    docker: Digest: sha256:81a1ab6955f8a17045fb4c2866b21c91445837507e86d489b03744557e6ed209
    docker: Status: Image is up to date for python:3.6
==> docker: Starting docker container...
    docker: Run command: docker run -v /Users/wes/.packer.d/tmp/packer-docker280972994:/packer-files -d -i -t python:3.6 /bin/bash
    docker: Container ID: e2f0f1a6dfde1c3c6bb002289c333f5ac7d7906dbe1990033776ef21029dc85e
==> docker: Committing the container
    docker: Image ID: sha256:3d77a9fa1feba6e918c5f7bb1645103203d21ad580057df0b3f8d0b1ba6d04c0
==> docker: Killing the container: e2f0f1a6dfde1c3c6bb002289c333f5ac7d7906dbe1990033776ef21029dc85e
==> docker: Running post-processor: docker-tag
    docker (docker-tag): Tagging image: sha256:3d77a9fa1feba6e918c5f7bb1645103203d21ad580057df0b3f8d0b1ba6d04c0
    docker (docker-tag): Repository: python-no-cmd-test:latest
Build 'docker' finished.

==> Builds finished. The artifacts of successful builds are:
--> docker: Imported Docker image: sha256:3d77a9fa1feba6e918c5f7bb1645103203d21ad580057df0b3f8d0b1ba6d04c0
--> docker: Imported Docker image: python-no-cmd-test:latest

$ docker run -it python-no-cmd-test
root@5e4eecf1571f:/# exit
exit

$ docker run -it python:3.6
Python 3.6.2 (default, Jul 24 2017, 19:47:39)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

Note how the test image drops me into bash, whereas the non-packer based image drops me into a python shell.

https://github.com/docker-library/python/blob/d3c5f47b788adb96e69477dadfb0baca1d97f764/3.6/jessie/Dockerfile#L95

Bumped into the same problem and here's what I found:
The thing here is how docker commit works - it applies the entrypoint and command of the container currently running. And if you see how packer runs the images by default (https://www.packer.io/docs/builders/docker.html#run_command), the command is indeed /bin/bash, which gets saved into the image.
Setting "run_command": ["-d", "{{.Image}}"] in the template saved my day in the end.

That said, at least a note in the docs could be really useful, given how the default behaviour is misleading.

@mikeroll Hey i have same issue, CMD doesn't execute, i tried yours but my packer container exits as soon as it starts. Can you share your file?

I also faced this issue, On spending some time I realized that CMD in packer by default takes /bin/bash. So I dropped CMD and on ENTRYPOINT provided two commands separated by &&. That worked for me which is little raw workaround.

Hey Packer maintainers.

Can we get an option that configures the commit option to not override any preexisting (set in your source FROM image) CMD and ENTRYPOINT configs which your base image relies on?
Defaulting to bin/shis not the expected behavior for someone (pretty much most devs) that have worked with Dockerfiles before.

Thanks in advance.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shashanksinha89 picture shashanksinha89  路  3Comments

wduncanfraser picture wduncanfraser  路  3Comments

paulcdejean picture paulcdejean  路  3Comments

znerd picture znerd  路  3Comments

Tensho picture Tensho  路  3Comments