ansible-container icon indicating copy to clipboard operation
ansible-container copied to clipboard

Preserve CMD from base image

Open chouseknecht opened this issue 8 years ago • 5 comments

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.

chouseknecht avatar May 01 '17 13:05 chouseknecht

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.

j00bar avatar May 01 '17 18:05 j00bar

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'
[
  ""
]

lorin avatar May 02 '17 00:05 lorin

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!

j00bar avatar May 02 '17 16:05 j00bar

same goes for entrypoint

hans-d avatar Dec 01 '17 22:12 hans-d

+1

mixpix3ls avatar Feb 06 '18 18:02 mixpix3ls