Simple steps to debug docker build

Le Vuong - Nov 6 - - Dev Community

Below are steps to debug docker build. In this example, docker is a python app, but the same logic apply to other languages and frameworks.

  1. In the Dockerfile, comment the lines that cause the build to fail and all other lines below that; Then add below line to the end of the Dockerfile.

CMD ["bash"]

  1. Build again (this time it should success) and start the container.
    docker run <image name>

  2. Connect to the container: docker exec -it <container> bash

  3. Run the steps that cause the build error (in Dockerfile).
    Eg. pip install -s requirements.txt

  4. Investigate and try to fix the failed commands.

  5. Continue with next other commands in the Dockerfile until everything is ok.

  6. When finished, uncomment the commented lines in Dockerfile in step 1.

  7. Try and build Dockerfile again.

References:

  • How to build docker
  • How to dockerize an app
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .