How can I inspect the file system of a failed `docker build`?

后端 未结 5 581
孤独总比滥情好
孤独总比滥情好 2020-12-12 08:38

I\'m trying to build a new Docker image for our development process, using cpanm to install a bunch of Perl modules as a base image for various projects.

<
5条回答
  •  没有蜡笔的小新
    2020-12-12 09:18

    The top answer works in the case that you want to examine the state immediately prior to the failed command.

    However, the question asks how to examine the state of the failed container itself. In my situation, the failed command is a build that takes several hours, so rewinding prior to the failed command and running it again takes a long time and is not very helpful.

    The solution here is to find the container that failed:

    $ docker ps -a
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                          PORTS               NAMES
    6934ada98de6        42e0228751b3        "/bin/sh -c './utils/"   24 minutes ago      Exited (1) About a minute ago                       sleepy_bell
    

    Commit it to an image:

    $ docker commit 6934ada98de6
    sha256:7015687976a478e0e94b60fa496d319cdf4ec847bcd612aecf869a72336e6b83
    

    And then run the image [if necessary, running bash]:

    $ docker run -it 7015687976a4 [bash -il]
    

    Now you are actually looking at the state of the build at the time that it failed, instead of at the time before running the command that caused the failure.

提交回复
热议问题