49

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

Tal
  • 7,549
  • 6
  • 37
  • 61

2 Answers2

62

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".

sk8terboi87 ツ
  • 3,219
  • 3
  • 32
  • 45
VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
  • 1
    minor typo, it is `docker inspect -f '{{.Config.Cmd}}' ` , not `docker inspect -f '{{.config.Cmd}}' ` – user2915097 May 25 '15 at 20:06
  • @user2915097 Thank you. I have edited the answer accordingly. – VonC May 25 '15 at 20:08
  • 1
    while 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
3

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,028
  • 11
  • 12