Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use the "git-like" capabilities of Docker?

I'm specifically interested in how I run or roll back to a specific version of the (binary) image from docker, and have tried to clarify this question to that effect.

The Docker FAQ it says:

Docker includes git-like capabilities for tracking successive versions of a container, inspecting the diff between versions, committing new versions, rolling back etc. The history also includes how a container was assembled and by whom, so you get full traceability from the production server all the way back to the upstream developer.

Google as I may, I can find no example of "rolling back" to an earlier container, inspecting differences, etc. (Obviously I can do such things for version-managed Dockerfiles, but the binary Docker image / container can change even when the Dockerfile does not, due to updated software sources, and I'm looking for a way to see and roll back between such changes).

For a basic example: imagine I run

docker build -t myimage .

on a Dockerfile that just updates the base ubuntu:

FROM ubuntu:14:04
RUN apt-get update -q && apt-get upgrade -y

If I build this same image a few days later, how can I diff these images to see what packages have been upgraded? How can I roll back to the earlier version of the image after re-running the same build command later?

like image 719
cboettig Avatar asked Aug 15 '14 23:08

cboettig


People also ask

What is the difference between Git and Docker?

. Git is the leading version control system for software development. The Dockerfile, on the other hand, contains all the commands to automatically build an image of our application. These two products are the perfect combination for anyone seeking to adopt DevOps.

How do I run a Docker command in GitHub action?

12 steps: - name: Log the parent container node version run: | node -v # Echo the node version of the parent container - name: Log the step container node version uses: docker://node:12.14.1-alpine3.10 with: entrypoint: usr/local/bin/echo args: -v # Echo the node version of this step container based on this 12.14.

How do I connect GitHub to Docker?

Link to a GitHub user accountLog in to Docker Hub using your Docker ID. Click Account Settings in the top-right dropdown navigation, then open Linked Accounts. Click Connect for the source provider you want to link.


1 Answers

Technically we are only rolling back AUFS layers, not necessarily rolling back history. If our workflow consists of interactively modifying our container and committing the changes with docker commit, then this really does roll back history in the sense that it removes any package updates we applied in later layers, leaving the versions installed in earlier layers. This is very different if we rebuild image from a Dockerfile. Then nothing here is letting us get back to the previous version we had built, we can only remove steps (layers) from the Dockerfile. In other words, we can only roll back the history of our docker commits to an image.

It appears the key to rolling back to an earlier version of a docker image is simply to point the docker tag at an earlier hash.

For instance, consider inspecting the history of the standard ubuntu:latest image:

docker history ubuntu:latest

Shows:

IMAGE               CREATED             CREATED BY                                      SIZE
ba5877dc9bec        3 weeks ago         /bin/sh -c #(nop) CMD [/bin/bash]               0 B
2318d26665ef        3 weeks ago         /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/   1.903 kB
ebc34468f71d        3 weeks ago         /bin/sh -c rm -rf /var/lib/apt/lists/*          8 B
25f11f5fb0cb        3 weeks ago         /bin/sh -c echo '#!/bin/sh' > /usr/sbin/polic   194.5 kB
9bad880da3d2        3 weeks ago         /bin/sh -c #(nop) ADD file:de2b0b2e36953c018c   192.5 MB
511136ea3c5a        14 months ago    

                                               0 B

Imagine we want to go back to the image indicated by hash 25f:

docker tag 25f ubuntu:latest
docker history ubuntu:latest

And we see:

IMAGE               CREATED             CREATED BY                                      SIZE
25f11f5fb0cb        3 weeks ago         /bin/sh -c echo '#!/bin/sh' > /usr/sbin/polic   194.5 kB
9bad880da3d2        3 weeks ago         /bin/sh -c #(nop) ADD file:de2b0b2e36953c018c   192.5 MB
511136ea3c5a        14 months ago                                                       0 B

Of course, we probably never want to roll back in this way, since it makes ubuntu:latest not actually the most recent ubuntu in our local library. Note that we could have used any tag we wanted, e.g.

docker tag 25f ubuntu:notlatest

or simply launched the old image by hash:

docker run -it 25f /bin/bash

So simple and yet so neat. Note that we can combine this with docker inspect to get a bit more detail about the metadata of each image to which the Docker FAQ refers.

Also note that docker diff and docker commit are rather unrelated to this process, as they refer to containers (e.g. running images), not to images directly. That is, if we run an image interactively and then add or change a file on the image, we can see the change (between container) by using docker diff <Container-id> and commit the change using docker commit <Container id>.

like image 99
cboettig Avatar answered Sep 29 '22 11:09

cboettig