When I include a Docker run_command in my Packer template, it appears that Packer attempts to run that command in the Docker image before any of the shell provisioning happens. This causes the build to fail because the run_command is dependent on the shell provisioning.
I think it's likely that I'm doing something wrong here, but can't figure out what that is. I'm happy to provide more details if it will help.
$ docker --version
Docker version 1.8.3, build f4bf5c7
$ packer --version
0.8.6
$ sudo packer build packer.json
docker output will be in this color.
==> docker: Creating a temporary directory for sharing data...
==> docker: Pulling Docker image: ubuntu:12.04
docker: 12.04: Pulling from library/ubuntu
docker: c0de77b824d9: Already exists
docker: 7f183271ade4: Already exists
docker: 02cc7e934fcc: Already exists
docker: fd97fd3cdea7: Already exists
docker: Digest: sha256:6947af68273664ce3d79b5456c015a4410eeb2fe14b8640ea0b043e888cc1358
docker: Status: Image is up to date for ubuntu:12.04
==> docker: Starting docker container...
docker: Run command: docker run -v /tmp/packer-docker422456728:/packer-files ubuntu:12.04 /bin/sh -c 'cd /opt/strato && npm start'
==> docker: Error running container: Docker exited with a non-zero exit status.
==> docker: Stderr: Error response from daemon: Cannot start container 674739e4b82eb22bed369dad41f29a18abb1b12d19399984ad175cf57b6d594a: [8] System error: exec: "/bin/sh -c 'cd /opt/strato && npm start'": stat /bin/sh -c 'cd /opt/strato && npm start': no such file or directory
==> docker:
Build 'docker' errored: Error running container: Docker exited with a non-zero exit status.
Stderr: Error response from daemon: Cannot start container 674739e4b82eb22bed369dad41f29a18abb1b12d19399984ad175cf57b6d594a: [8] System error: exec: "/bin/sh -c 'cd /opt/strato && npm start'": stat /bin/sh -c 'cd /opt/strato && npm start': no such file or directory
I may simply be misinterpreting the purpose of run_command
. I assumed that its purpose is to specify which command gets run when issuing docker run
on the image resulting from the Packer build. Is that correct?
@ottumm Sorry about the confusion here. The run_command
is actually working as intended in this case. It's meant to provide you a means to customize how the container is started before the provisioning scripts are run. If you reference the docs you'll notice that the default run_command
is:
docker run -d -i -t {{.Image}}
You might customize this to add flags or to override the default entry point into the container _at build time_. For instance if the default entry point in your container is /usr/bin/redis
but you want /bin/bash
instead you could change that here.
Also please note that docker builds in packer don't work the same was as builds using a Dockerfile. Most obviously, they don't use a Dockerfile. The docker docs page has more details about this.
I'm going to close this but please ping / reopen if this does not resolve your issue.
Thanks for the explanation; that makes sense. Is there any way to set the default docker run
command for the built image (equivalent to the Dockerfile CMD instruction)?
+1
I'd love to see entrypoint functionality implemented in Packer.
Seems there's some solutions for it; none of which are ideal :/
Super odd this is not a thing already hey
@yoshuawuyts Also see #2180
Most helpful comment
+1
I'd love to see entrypoint functionality implemented in Packer.