Thursday, March 26, 2020

How investigate a failed Docker build

While working on a recent task, I got stuck with a Dockerfile which was failing to build. The failing container was failing at one step of building with native extensions of some Ruby gems. I wanted get into the container to see what the logs were saying.

This is the code snippet I used to do so:

Step 1: Get the container ID

by running

$ docker ps -a

I could look for the CONTAINER ID of the failing container.

Step 2: Commit container to an image

Using the container ID from the previous step, commit the container to create an image with its current state
$ docker commit ca73ac766f36
sha256 5b4586632f690964d3a2e2b958cf6d211bc924e47e80a9bc4a84c53779f39f79

Step 3: Run the image

Using the sha256 code from the previous step, run the image with bash and debug the image however you want. You don't have to use the full sha256 string

$ docker run -it 5b4586632f [bash -il]

And that's it!

No comments:

Post a Comment