Docker Community Forums

Share and learn in the Docker community.

Question regarding CMD instruction

hi all, I’ve look on CMD argument on the net and understand that the CMD argument is used to run the container.
My question is how do we know the command to run the app?

Let’s say that I used this odoo image and let’s say that I want to add non-root USER so the format of dockerfile would be something like this

FROM odoo:latest
USER non-root
CMD ???

Just like the example above, how do I know what command should I write on that CMD cause sometime I found people using [/the_name_of_the_app], and when I used it the images returns an error.

Well, that depends if there’s also an ENTRYPOINT defined. From the documentation:

The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.

Be sure to read about the different CMD formats in the documentation. And make sure to read Understand how CMD and ENTRYPOINT interact. In those, you can interpret “Unlike the shell form, the exec form does not invoke a command shell” as: when using the shell form, and if no ENTRYPOINT is defined, then Docker defaults to /bin/sh -c.

Next, look at the source’s Dockerfile which ends with the following:

...
ENTRYPOINT ["/entrypoint.sh"]
CMD ["odoo"]

And the provided entrypoint.sh which after some initialization parses its arguments as:

This exposes that CMD, which is passed as argument(s) to ENTRYPOINT, could be -- or odoo with optional additional 2nd, 3rd, …, Nth arguments, for which scaffold as a 2nd argument would not wait for the database, and in both cases would just pass the 2nd, 3rd, … arguments to the odoo command (using "$@"). Or could be -anything with a leading dash (the -*) part), again with optional additional arguments, which would again be passed as arguments to the odoo command. Or could be just anything (the *) catch all last option) which would simply be executed as is. All after the top parts of that entrypoint have completed.

In general, you’d just need some documentation rather than trying to decipher the scripts. Or just don’t specify anything to use the defaults from the base image.

1 Like