So I am creating a docker image with packer. The template defines the provisioners and builders etc. The builder section looks like this:
{
"builders": [
{
"type": "docker",
"image": "ubuntu:latest",
"export_path": "image.tar",
"changes": [
"USER test",
"WORKDIR /tmp",
"VOLUME /data",
"EXPOSE 21 22",
"CMD sudo myprogram"
]
}
]
}
When running packer against the template, the output is an image.tar
file.
I can then import it: docker import image.tar
.
And then I start like this docker run -p 21:21 -it --rm 52c0b0362362 bash
.
I want whenever the image is started that automatically sudo myprogram
is executed. However it does not seem to work, even tho the template validated successfully. I also tried instead of specifying CMD sudo myprogram
to set it as entrypoint like so: ENTRYPOINT sudo myprogram
.
Neither worked. How can I make sure whenever my image is started, this command is automatically executed? It must be run as root/with sudo, that's important.
sudo
? Could you add a sample program so people could reproduce the issue? Please add the complete packer.json file and describe the exact commands that you issued, e.g.packer build file.json
CMD
you could tryENTRYPOINT
. There is a StackOverflow post that describes the difference.docker run -it -p 21:21 --rm myimage
without thebash
command. You should see some output.