What docker init does
- Run
docker initin your project directory (for example, aftercd my-project). - The command runs a short interactive prompt, inspects files in the directory, and infers the language (for example,
package.json→ Node,go.mod→ Go,requirements.txt→ Python). - It asks a few language-specific follow-up questions: runtime version, package manager, entrypoint file, port to expose, etc.
- With a few quick answers, Docker Init generates a minimal, sensible set of Docker assets to get you started.
What files docker init generates
Docker Init produces four files by default:
Below are the exact examples Docker Init typically generates.
1) Dockerfile (multi-stage, production-ready starter)
This Dockerfile demonstrates recommended patterns:ARG for version, a slim base image, multi-stage builds, dependency caching, NODE_ENV, non-root user, EXPOSE, and a simple CMD.
2) .dockerignore (examples for common languages)
Docker Init populates.dockerignore with reasonable entries for the detected language so your build context stays small and builds are faster.
3) compose.yaml (starter Compose file)
A minimal Compose file is generated to run the service locally with the port mapped.4) README.Docker.md (quick start)
A short README explains how to build and run the generated setup.How Docker Init works (and what it doesn’t do)
Docker Init is a template-based scaffolder, not an AI tool. The CLI ships with a small set of static templates (usually one per supported language) and fills in the blanks based on your answers. It does not analyze your source code, so it won’t automatically detect custom build steps, system packages, or libraries that require special handling.Docker Init gives a sensible starting point for typical apps in each language. Expect to make hand edits afterward to add project-specific build steps, system dependencies, environment variables, or custom entrypoints.
Supported languages
Docker Init includes templates for common platforms: Go, Python, Node, Rust, ASP.NET Core, PHP with Apache, and Java. If your project is not recognized, choose the “Other” option and Docker Init will drop a minimal, generic Dockerfile for you to customize.
Existing files: docker init asks before overwriting
If aDockerfile, .dockerignore, or compose.yaml already exists, docker init prompts before overwriting them so it’s safe to run in projects that already contain Docker assets.
Example session:
When prompted about overwriting existing files, choose carefully. If you decline, Docker Init will not overwrite your current files.
When to use docker init
- Starting a new project and you want a quick, recommended Dockerfile and companion files.
- You want a time-saving scaffold that follows best practices: multi-stage builds, slim base images, and non-root users.
- You need a reproducible starting point to iterate from.
When not to use docker init
- You already have a working
Dockerfilethat fits your needs — no need to replace it. - Your project has unusual requirements (native dependencies, custom build tooling, or special runtime constraints) that the templates don’t cover. In those cases, write or customize the Dockerfile by hand.
create-react-app or cargo new): a solid starting line, not the finished product.
Links and references
- Docker CLI reference: https://docs.docker.com/engine/reference/commandline/cli/
- docker compose: https://docs.docker.com/compose/
- create-react-app: https://create-react-app.dev/
- cargo new: https://doc.rust-lang.org/cargo/commands/cargo-new.html
docker init, then customize the generated files for your project’s specific needs.