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– 030 Dec 05 '19 at 15:48CMDyou could tryENTRYPOINT. There is a StackOverflow post that describes the difference. – 030 Dec 05 '19 at 15:58docker run -it -p 21:21 --rm myimagewithout thebashcommand. You should see some output. – Hedi Nasr Dec 06 '19 at 08:58