I have a docker image installed and I'd like to check what is its CMD command. Is there any cli command to do so? for example, I'd like it to tell me that this docker image CMD is ["rails","server"]
Asked
Active
Viewed 2.2k times
2 Answers
74
You can use the docker inspect
command
docker inspect --format='{{.Config.Cmd}}' <image:tag>
docker inspect -f '{{.Config.Cmd}}' <image:tag>
That is used, for instance, to "list full command of running/stopped container in Docker".
As noted in the comments by user2915097 and Lenormju, an alternative would be, using docker history --no-trunc
:
docker history --no-trunc zenithar/nano-nginx | awk ' NR==2 {print}'

VonC
- 1,262,500
- 529
- 4,410
- 5,250
-
1while docker inspect is THE way to go, as a docker image has this command in his last layer, a trick could be to use something like `docker history zenithar/nano-nginx | awk ' NR==2 {print}'` but the drawback is that the command is truncated. – user2915097 May 26 '15 at 05:37
-
1@user2915097 does a dockerfile has to terminate with CMD though? – VonC May 26 '15 at 05:39
-
no, it may be a CMD, ENTRYPOINT, or nothing. We are back at docker inspect so :-) – user2915097 May 26 '15 at 06:14
-
@user2915097 now there is a `--no-trunc` option for the [`docker history` command](https://docs.docker.com/engine/reference/commandline/history/) – Lenormju Jul 11 '22 at 10:08
-
1@Lenormju Thank you for this feedback. I have included this alternative (amended with `--no-trunc` in the answer for more visibility. – VonC Jul 11 '22 at 10:26
4
If it's running, you can use
docker inspect -f "{{.Path}} {{.Args}} ({{.Id}})" $(docker ps -a -q)
Shamlessley pulled from this response

Mike Holdsworth
- 1,088
- 11
- 12