5
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Dockerのイメージを任意の処理までロールバックする

Posted at

わかりやすいコマンドがなかったのでメモ

やりたいこと

Dockerfileからbuildしたイメージについて、任意の中間レイヤまで戻したい

こういうDockerfileをbuildしたとして、途中まで戻したい

Dockerfile
FROM alpine:latest

RUN echo 'ここまで'
RUN echo 'なにか'
RUN echo 'てきとうな'
RUN echo 'しょり' #ここまで戻したい
RUN echo 'ふような'
RUN echo 'しょり'

docker build -t test . && docker history test するとこう

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
3f5cdea9489f        3 seconds ago       /bin/sh -c echo 'しょり'                           0 B
eedfad20e5b5        4 seconds ago       /bin/sh -c echo 'ふような'                          0 B
c6f5a78d6c0a        6 seconds ago       /bin/sh -c echo 'しょり' #ここまで戻したい                   0 B
b0a1ad3df9a4        7 seconds ago       /bin/sh -c echo 'てきとうな'                         0 B
398af1df101f        9 seconds ago       /bin/sh -c echo 'なにか'                           0 B
ccbb3b8d5aeb        10 seconds ago      /bin/sh -c echo 'ここまで'                          0 B
baa5d63471ea        8 weeks ago         /bin/sh -c #(nop) ADD file:7afbc23fda8b0b3872   4.803 MB

戻し方

戻したいレイヤにタグを付ける
docker tag 任意のレイヤ test

結果

docker tag c6f5a78d6c0a test

IMAGE               CREATED              CREATED BY                                      SIZE                COMMENT
c6f5a78d6c0a        About a minute ago   /bin/sh -c echo 'しょり' #ここまで戻したい                   0 B
b0a1ad3df9a4        About a minute ago   /bin/sh -c echo 'てきとうな'                         0 B
398af1df101f        About a minute ago   /bin/sh -c echo 'なにか'                           0 B
ccbb3b8d5aeb        About a minute ago   /bin/sh -c echo 'ここまで'                          0 B
baa5d63471ea        8 weeks ago          /bin/sh -c #(nop) ADD file:7afbc23fda8b0b3872   4.803 MB

やったぜ。

5
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?