# Generate a Dockerfile
Source: https://docs.infraista.com/en/developer-tools/dockerfile-studio/generate-a-dockerfile



**Before you start:** connect GitHub, GitLab or Bitbucket. Git connections are shared by Containers,
Pipelines, Code Security and Dockerfile Studio (see
[Create a pipeline](/en/developer-tools/pipelines/create-a-pipeline)).

## 1. Choose a repository [#1-choose-a-repository]

1. Open **Dockerfile Studio** and select **Generate Dockerfile**.
2. Pick the **Git connection** and the repository.
3. Choose the **Branch**, and the **Folder** of the app in a monorepo (leave `.` for the whole
   repository).
4. Select **Analyze repository**.

The repository is cloned into an isolated, single-use sandbox and read there. This usually takes a few
seconds.

<Shot name="developer-tools/dockerfile-studio/new" alt="Generate Dockerfile, with the steps Repository, Analyze and Options" />

## 2. Check what was detected [#2-check-what-was-detected]

**What we detected** lists the language, framework, package manager, start command, worker command,
port, test command, health check path and the services the app uses. Values marked **High** come straight from a
manifest or lockfile; **Medium** ones were inferred and are worth a look. Correct anything that's off:
the Dockerfile is written from these values.

If the repository already has a Dockerfile, Dockerfile Studio writes an improved one.

## 3. Choose options [#3-choose-options]

| Option                         | Choices                                                                                                                                                         |
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Files to generate**          | Dockerfile and .dockerignore always; **docker-compose.yml** for local development (the app, its worker and the services it uses)                                |
| **Target**                     | **Production** (small runtime image, production dependencies only) or **Development** (a dev stage with dev dependencies and reload)                            |
| **Base image**                 | **Slim** (Debian slim, compatible with prebuilt packages), **Alpine** (smallest, uses musl), or **Distroless** (no shell or package manager in the final image) |
| **Architecture**               | amd64, arm64 or both                                                                                                                                            |
| **Add HEALTHCHECK**            | With the path found in your code, or a default you should check                                                                                                 |
| **Pin base image by digest**   | Adds `@sha256:…` for reproducible builds; someone has to bump it to get security patches                                                                        |
| **Run tests during the build** | A failing test stops the image from being built                                                                                                                 |
| **Extra instructions**         | Anything else, in plain language                                                                                                                                |

Every generated Dockerfile runs the app as a non-root user (`app`, uid 10001).

The summary shows whether this generation uses one of your included generations or is billed.

## 4. Generate [#4-generate]

Select **Generate**. Writing the files usually takes 10–40 seconds, and you can leave the page; you get
a notification when it's ready.

<Shot name="developer-tools/dockerfile-studio/result" alt="A generated Dockerfile with line explanations, best-practice checks, the estimated image size and versions" />

## Read the result [#read-the-result]

* **Files**: click a line or a numbered marker to see what it does.
* **About this image**: the estimated image size, base image and architecture.
* **Best-practice checks**: real checks of the files, such as a non-root user, pinned base image
  versions, no secrets in `ENV` or `ARG`, and your organization's
  [rules](/en/developer-tools/dockerfile-studio/settings-and-limits#rules-for-every-dockerfile).
* **Try it locally**: the commands to build and run it.
* **Download files** as they are in the version you're viewing.

## If it failed [#if-it-failed]

Open the generation to see why it didn't finish, then select **Try again**.

## Related [#related]

* [Refine and open a pull request](/en/developer-tools/dockerfile-studio/refine-and-open-a-pull-request)
* [Settings and limits](/en/developer-tools/dockerfile-studio/settings-and-limits)
