Preserve CMD from base image
Hi all:
I've noticed that when I use Ansible Container to build an image, it does not preserve the CMD of the base image.
For example, if I use "nginx" as my base image, the CMD of the original image is:
CMD ["nginx", "-g", "daemon off;"]
Or, if we inspect it:
$ docker inspect nginx | jq '.[0].ContainerConfig.Cmd'
[
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"nginx\" \"-g\" \"daemon off;\"]"
]
If I create a new image from nginx using an entry like this:
services:
ac-nginx:
from: nginx
roles: nginx
- ghost-nginx
Then, in the image generated by Ansible Container, CMD becomes:
$ docker inspect ans-con-ac-nginx | jq '.[0].ContainerConfig.Cmd'
[
"sh",
"-c",
"while true; do sleep 1; done"
]
(I assume that's from here).
I can work around this by explicitly adding a "command" field to the service entry:
command: [/bin/sh, -c, nginx, -g, daemon off;]
However, it wasn't obvious to me what the issue was. I think it would be a useful feature if Ansible Container preserved the CMD of the parent image by default.
To my knowledge, this is NOTABUG.
ContainerConfig is metadata the Docker engine relies upon during the rebuild process. The Config section is what the actual runtime defaults are for the container image. So long as Config.Cmd is correct, the behavior is correct.
It does appear that the image that Ansible Container creates has a blank CMD field if there's no "command" field explicitly specified in container.yml:
For example, here's the original image:
$ docker inspect nginx | jq '.[0].Config.Cmd'
[
"nginx",
"-g",
"daemon off;"
]
Here's the one generated by Ansible Container when no "command" is specified:
$ docker inspect ans-con-ac-nginx | jq '.[0].Config.Cmd'
[
""
]
Agreed - thank you, and apologies for my misunderstanding.
In container.utils:metadata_to_image_config, we're starting with blank defaults for every configuration string. We should pull the settings instead from the from: image.
Thank you for reporting this!
same goes for entrypoint
+1