Yves Nicolas
Yves Nicolas

Reputation: 7901

How to see commit message from docker images

I am new to docker and begin playing with it. I have created a few images from committing a few changes. Started with

sudo docker run -i -t ubuntu /bin/bash

doing a few installs, exited and did

sudo docker commit -m="my first message" innocent_dockernovice sandbox/yves:s1

and repeting the process

sudo docker run -i -t sandbox/yves:sN /bin/bash

doing stuff in shells, exiting and

sudo docker commit -m="what I did in step N" happy_dockeruser sandbox/yves:sN+1

Now I want to go back to a previous step image and would like to list all the messages doing a sudo docker image -m kind of command similar to a git log one. What is the best way to do it?

Upvotes: 24

Views: 22623

Answers (3)

Vasily802
Vasily802

Reputation: 1858

You can use docker history command:

$ docker history <image hash>

Sample output:

IMAGE               CREATED             CREATED BY        SIZE          COMMENT
02c473b152e3        9 days ago          /bin/bash         1.577 kB      modified init.sh
39a27fe266c4        9 days ago          /bin/bash         1.472 kB      modified init.sh
1a8dae63b9fe        9 days ago          /bin/bash         1.457 kB      modified init.sh

Upvotes: 14

Yarco
Yarco

Reputation: 803

To make things simple, i did a simple bash script in github gist: docker-log

#!/usr/bin/env bash

DOCKER=`which docker`

if [ "$#" -ne 1 ]; then
  echo "Usage: $0 IMAGE"
  exit 0
fi

for commit in $($DOCKER history $1 | sed 1d | awk '{ print $1 }')
do
  content="$commit
$($DOCKER inspect $commit | tr -d '\"' | grep 'Created\|Author\|Comment')"
  echo "$content"
done

Snapshot for usage:

enter image description here

Upvotes: 18

Matt Carrier
Matt Carrier

Reputation: 5992

You can view commit messages by using docker inspect on the commit hash displayed afterwards. To view more of them you must do it recursively.

$ docker commit -m "added test file" sick_morse
61efdbd141dc5fb1c289ed5151f3ce7b5985a5829bd92ba322ad6061cb1eee21
$ docker inspect 61efdbd141dc5fb1c289ed5151f3ce7b5985a5829bd92ba322ad6061cb1eee21 | grep added
    "Comment": "added test file",

Found info here

This would let you view the messages for the top 3 most recent comments.

$ docker images -a --no-trunc | head -n4 | grep -v "IMAGE ID" | awk '{ print $3 }' | xargs docker inspect | grep Comment

Upvotes: 23

Related Questions