My Docker build fails. How do I fix it?

Also searched as: Docker build failed · Docker build failed with exit code 1 · Docker build failed to solve · Docker build fails: COPY failed: no source files were specified · Docker build fails at npm install

Updated 3 October 2026

Short answer

Find the step that failed. Docker prints the Dockerfile line it was running, with the error underneath. On old projects it's usually one of three things: the base image is outdated or its tag has gone, a COPY refers to a file that isn't in the build context (or is excluded by .dockerignore), or installing dependencies inside the image fails, for the same reasons it would fail on a laptop.

What's the problem

The project has a Dockerfile, which was meant to make it run anywhere. Now docker build stops with "failed to solve", "exit code 1", "COPY failed", or an error from npm install or pip install halfway through.

Why it happens

  • The base image aged. FROM node:14 or FROM python:3.7 pulls a runtime that's long out of support, and current packages won't install on it. Or the image tag the Dockerfile names no longer exists.
  • The file isn't in the context. Docker can only copy files inside the folder you build from, and minus anything listed in .dockerignore. A COPY of a file outside it, or an ignored one, fails.
  • Installs inside the image fail. The dependency install step meets every problem an old project has: a lockfile out of sync, packages that need build tools the image doesn't have, packages that no longer exist.
  • The machine runs out of memory during big builds, especially on small build servers.

How to fix it

  1. Get the full output: docker build --progress=plain --no-cache . and find the first error.
  2. Check the base image. Does the tag still exist? Is the runtime version supported? Pick a currently supported version, and pin it exactly.
  3. For COPY errors, check the path is relative to the folder you're building from, the file exists there, and .dockerignore doesn't exclude it.
  4. For dependency install errors, fix them the same way as outside Docker. See npm install fails or Python dependencies won't install. Copy the lockfile into the image and install from it.
  5. Add any system packages the dependencies need to build, in the Dockerfile.
  6. For memory errors, give Docker more memory or build on a bigger machine.
  7. Once it builds, run it and check it starts. See Docker container won't start.

When to call Preventionlabs

If updating the base image and fixing one install gets it building, you're through. Call us when the image depends on runtimes and packages that no longer exist, and modernising the Dockerfile means modernising the whole app. A resurrection delivers an app that builds and starts on maintained dependencies, deployed in your own hosting account.

Submit your project for a free assessment

Free assessment. $10,000 AUD flat to get it live, only if we take it on and you go ahead.

Sources

  1. Docker: Build contextofficial docsThe build context is the set of files that your build can access.
  2. Docker: Build context: .dockerignore filesofficial docsYou can use a .dockerignore file to exclude files or directories from the build context.
  3. npm: npm ciofficial docsIf dependencies in the package lock do not match those in package.json, npm ci will exit with an error, instead of updating the package lock.
← All of It used to work