Docker Community Forums

Share and learn in the Docker community.

How to debug build failures


(Miniserver) #1

If I’m building an image and I have a line of code in the build file that causes the build to fail, how can I interactively run that container to check the file system and etc?


(Nathan Le Claire) #2

Use the image IDs that docker build spits out with docker run. Notice how I run the ID from the last “good” line here.

$ echo 'from debian
env FOO=BAR
env QUUX=SPAM
run myprog
' | docker build -
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM debian
 ---> 9a02f494bef8
Step 2 : ENV FOO BAR
 ---> Running in 4def0346ae9d
 ---> b6373963d411
Removing intermediate container 4def0346ae9d
Step 3 : ENV QUUX SPAM
 ---> Running in 7cdc5a97b776
 ---> a7c9a0d24fe3
Removing intermediate container 7cdc5a97b776
Step 4 : RUN myprog
 ---> Running in d590aa9618dc
/bin/sh: 1: myprog: not found
The command '/bin/sh -c myprog' returned a non-zero code: 127

$ docker run -ti a7c9a0d24fe3 env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=ff5acdf0f353
TERM=xterm
FOO=BAR
QUUX=SPAM
HOME=/root