ansible / ansible-container

DEPRECATED -- Ansible Container was a tool to build Docker images and orchestrate containers using only Ansible playbooks.
GNU Lesser General Public License v3.0
2.19k stars 394 forks source link

Preserve CMD from base image #470

Open chouseknecht opened 7 years ago

chouseknecht commented 7 years ago

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.

j00bar commented 7 years ago

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.

lorin commented 7 years ago

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'
[
  ""
]
j00bar commented 7 years ago

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!

hans-d commented 6 years ago

same goes for entrypoint

mixpix3ls commented 6 years ago

+1