Skip to content
Latchkey

Docker "docker init" - Template Overwrites or Fails Against Existing Files in CI

docker init scaffolds a Dockerfile, compose.yaml, and .dockerignore from a template. In CI it is the wrong tool: it is interactive, it can overwrite files you already maintain, and the generated template may not match your real build.

What this error means

A docker init step in CI hangs waiting for input, prompts to overwrite an existing Dockerfile/compose.yaml, or produces a template that then fails to build because it does not match the project’s actual stack.

docker init output
Dockerfile already exists in this directory. Do you want to overwrite it? Yes/No
# in CI this either hangs on the prompt or clobbers your maintained Dockerfile

Common causes

docker init is interactive

docker init walks an interactive wizard. In a non-interactive CI shell it blocks on prompts (or errors), which is not what a pipeline expects.

It overwrites existing build files

Run in a directory that already has a Dockerfile/compose.yaml, it offers to overwrite them - risking clobbering files you maintain by hand.

The generated template does not fit your stack

docker init guesses a template. The scaffold can reference the wrong base image, ports, or start command, so a build using it fails.

How to fix it

Do not run docker init in CI

Scaffolding is a one-time local task. Commit the resulting files and build from them in CI; do not regenerate during the pipeline.

Terminal
# locally, once:
docker init
git add Dockerfile compose.yaml .dockerignore && git commit -m "Add Docker scaffold"
# CI then just builds the committed files:
docker build -t myorg/api:1.4.2 .

Review and adapt the generated template

Treat the scaffold as a starting point and fix the base image, ports, and start command to match the app.

How to prevent it

  • Run docker init once locally, commit the output, and build it in CI.
  • Never regenerate scaffolding during a pipeline run.
  • Review the generated template so it matches your real stack.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →