0
votes

Describe the problem and include the following information:

Packer Version - 0.9.0
Host platform - Centos 7.2

I am trying to provision a docker container, and I need the container to have /lib/modules mounted to /lib/modules in the container. Whats strange is when I run the docker run command that Packer says its running, I am able to start the container and do what I need to do.

My Docker command that works -

docker run --privileged -t -i --net=host -v /lib/modules:/lib/modules 9a8c6ee5e82a /bin/bash -c 'sudo /sbin/service iptables restart'

Part of the template concerning this

{ "builders": [{ "type": "docker", "image": "my-img", "pull": false, "export_path": "docker-march.tar", "run_command": [ "--privileged", "-d", "-i", "-t", "--net=host", "-v /lib/modules:/lib/modules", "{{.Image}}", "/bin/sh" ] }],

And the error ==> docker: Error running container: Docker exited with a non-zero exit status. ==> docker: Stderr: flag provided but not defined: -v /lib/modules:/lib/modules

This is what it says its running

docker: Run command: docker run -v /home/my-user/.packer.d/tmp/packer-docker780723700:/packer-files --privileged -d -i -t --net=host -v /lib/modules:/lib/modules top-rhel6-base /bin/sh

Which when I run manually, works.

1

1 Answers

0
votes

So i figured out the solution to this. Packer wants the parameter '-v' to be in its own set of quotes, and then what you want to pass to -v on another line. So for example, this is what is working for me

run_command": [ "--privileged", "-d", "-i", "-t", "--net=host", "-v", " /lib/modules:/lib/modules", "{{.Image}}", "/bin/sh" ]

Here is what I did have that was not working

run_command": [ "--privileged", "-d", "-i", "-t", "--net=host", "-v /lib/modules:/lib/modules", "{{.Image}}", "/bin/sh" ]

If this isn't in the documentation (I didn't see it, but that doesn't mean its not there) it maybe should be?