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

0 votes

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.

While developing the Dockerfile, cpanm returns a failure code because some of the modules did not install cleanly.

I'm fairly sure I need to get apt to install some more things.

My question is, where can I find the /.cpanm/work directory quoted in the output, in order to inspect the logs? In the general case, how can I inspect the file system of a failed docker build command?

After biting the bullet and running a find I discovered

/var/lib/docker/aufs/diff/3afa404e[...]/.cpanm

Is this reliable, or am I better off building a "bare" container and running stuff manually until I have all the things I need?

Jul 30, 2018 in Docker by Hannah
• 14,080 points
47 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Everytime docker successfully executes a RUN command from a Dockerfile, a new layer in the image filesystem is committed. Conveniently you can use those layers ids as images to start a new container.

Take the following Dockerfile:

FROM busybox

RUN echo 'foo' > /tmp/foo.txt

RUN echo 'bar' >> /tmp/foo.txt

and build it:

$ docker build -t so-2622957 .

Sending build context to Docker daemon 47.62 kB

Step 1/3 : FROM busybox

 ---> 00f017a8c2a6

Step 2/3 : RUN echo 'foo' > /tmp/foo.txt

 ---> Running in 4dbd01ebf27f

 ---> 044e1532c690

Removing intermediate container 4dbd01ebf27f

Step 3/3 : RUN echo 'bar' >> /tmp/foo.txt

 ---> Running in 74d81cb9d2b1

 ---> 5bd8172529c1

Removing intermediate container 74d81cb9d2b1

Successfully built 5bd8172529c1

You can now start a new container from 00f017a8c2a6, 044e1532c690and 5bd8172529c1:

$ docker run --rm 00f017a8c2a6 cat /tmp/foo.txt

cat: /tmp/foo.txt: No such file or directory

$ docker run --rm 044e1532c690 cat /tmp/foo.txt

foo

$ docker run --rm 5bd8172529c1 cat /tmp/foo.txt

foo

bar

of course you might want to start a shell to explore the filesystem and try out commands:

$ docker run --rm -it 044e1532c690 sh     

/ # ls -l /tmp

total 4

-rw-r--r--    1 root     root             4 Mar  9 19:09 foo.txt

/ # cat /tmp/foo.txt

foo


When one of the Dockerfile command fails, what you need to do is to look for the id of the preceding layer and run a shell in a container created from that id:

docker run --rm -it <id_last_working_layer> bash -il

Once in the container:

  • try the command that failed, and reproduce the issue
  • then fix the command and test it
  • finally update your Dockerfile with the fixed command
answered Jul 30, 2018 by Kalgi
• 36,770 points
0 votes

Failed command is a build that has taken place several hours back, so rewinding the build to that stage is a waste of time.

Follow these steps instead

1) Find the container that failer

docker ps -a

2) Commit it to an image

docker commit 6934ada98de6

3) Run the image

 docker run -it 7015687976a4 [bash -il]

answered Aug 6, 2018 by Nilesh
• 6,900 points

Related Questions In Docker

0 votes
1 answer

How do I force Docker for a clean build of an image ?

You can try the following step: You have ...READ MORE

answered Sep 7, 2018 in Docker by Damon Salvatore
• 5,470 points
356 views
0 votes
1 answer

How do I copy a file from docker container to host?

Here is a way which you can ...READ MORE

answered Aug 27, 2018 in Docker by Damon Salvatore
• 5,470 points
1,104 views
0 votes
1 answer
0 votes
1 answer

What is a docker file? How do I create a docker image with dockerfile?

 A Dockerfile is a script/text configuration file that contains ...READ MORE

answered Jun 7 in Docker by Sirajul
• 940 points
20 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,140 points
81 views
+2 votes
11 answers
0 votes
2 answers

How to edit file after I shell to a docker container?

You can even install it using a ...READ MORE

answered Apr 23 in Docker by Ashish
1,988 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.