# Build: Dockerfile, Railpack and image > How Ployter produces your service's image, from GitHub or from a ready-made Docker image. Every service runs a Docker image. It comes from one of these paths: a build of your GitHub repository (automatic with Railpack, or with your Dockerfile) or a ready-made image from a registry. The build runs on the service's own server, and the image stays in the local Docker, with no registry in between. ## Choose the source Open the service, go to **Settings** and, under **Source**, choose **GitHub** or **Image**. ![Source and Deploy section in the web service's Settings tab](https://ployter.com/assets/docs/en/builds-settings-source.webp) ### GitHub | Field | What it is | | --- | --- | | **Repository** | The repository URL, e.g. `https://github.com/acme/loja`. | | **Branch** | The branch that goes live, e.g. `main`. | | **Credential** | The GitHub credential used to clone. **None (public)** only works for public repositories. | | **Folder (monorepo)** | The service's folder inside the repository, e.g. `apps/api`. Blank means the root. | | **Deploy on every push** | Turns on automatic deploys when there is a push to the branch. | With **Deploy on every push** turned on, each push to the branch triggers a deploy. With the GitHub App, this works with nothing to configure. With a token, the panel creates the webhook in the repository for you, and the token needs webhook permission: the `admin:repo_hook` scope on a classic token, or **Webhooks: Read and write** on a fine-grained one. See [Connect GitHub](https://ployter.com/en/docs/integrations/github/). > [!NOTE] > If the panel can't create the webhook (token without permission, repository from another account), it shows a warning when you save. Manual deploys keep working. ### Image Enter the image with its tag, e.g. `redis:7-alpine` or `mysql:8.4`. On every deploy the server pulls the image again. > [!NOTE] > The panel doesn't store registry logins: the image must be public. ## Automatic build (Railpack) With **Automatic (Railpack)**, the server analyzes the code and builds the image on its own. Railpack recognizes the language and framework (Node, PHP, Python, Ruby, Go and others) and decides the install, build and start command. In the **Deploy** section of the **Settings** tab, under **Image build**, you can replace each phase with your own script: - **Install**: blank means automatic (e.g. `npm install`, `composer install`). Filled in, it runs your script, one command per line. - **Build**: blank means automatic (e.g. `npm run build`). Filled in, it runs your script. - **Start**: blank uses the detected command. Fill it in to change it, e.g. `node dist/main.js`. After the first build, each blank phase shows what the automatic build runs, under **Automatic runs:**. Some details of the automatic build: - **Node**: the build gets more memory than Node's default: up to 60% of the server's memory, capped at what is free, between 1 GB and 8 GB, so large Next.js, Vite or TypeScript builds don't die with "heap out of memory". If you set `NODE_OPTIONS` in the variables, yours wins. - **PHP**: the extensions required by the `composer.json` dependencies are added automatically. For others, use the `RAILPACK_PHP_EXTENSIONS` variable (e.g. `gd,intl`). - **Variables**: the service's variables are passed to the build. This is needed for variables read at build time, such as `NEXT_PUBLIC_*` in Next.js. > [!TIP] > If the repository has a `Dockerfile` and the build is set to automatic, the panel warns you in **Settings** and in the build log. To use it, choose **Dockerfile**. ## Build with a Dockerfile Choose **Dockerfile** under **Image build** and fill in: - **Dockerfile path**: relative to the service's folder (or to the **Folder (monorepo)**). Default: `Dockerfile`. - **Start**: blank uses the Dockerfile's `CMD`. Filled in, it runs with `/bin/sh -c` in place of the image's `ENTRYPOINT`/`CMD`. The service's variables reach the build in two ways: - As `ARG`, only where the Dockerfile declares an `ARG` with the same name. - As a BuildKit secret, so you can use it without leaving the value in the image. ```dockerfile FROM node:22-alpine WORKDIR /app # As ARG: the value is available in this stage ARG NEXT_PUBLIC_API_URL COPY package*.json ./ # As secret: the value is not written to any layer RUN --mount=type=secret,id=NPM_TOKEN \ NPM_TOKEN=$(cat /run/secrets/NPM_TOKEN) npm ci COPY . . RUN npm run build CMD ["npm", "start"] ``` ## Shared build When several services use the same repository (for example, several sites with the same code and different variables), one of them can run the build and the others deploy the same image. 1. Open the service that will **use** the image and go to **Settings**. 2. In the **Shared build** card, under **Use the build from**, choose the service that runs the build. 3. Click **Save**. From then on: - A push to the repository doesn't build the follower service. It deploys together with the source service, after that service's build goes live. - The follower's **Deploy** button runs its own build, for that service only, with the latest commit in the repository. It stays on that version until the next build of the source service, which updates it again. Meanwhile, the card shows that the service is on its own build. - Redeploying, rolling back or changing variables on the source service doesn't touch the followers: only a new build of the source updates them all. - Each service keeps its own variables. > [!NOTE] > Shared builds only work between services on the same server, and aren't available for services with replicas. ## Upload the local folder with the CLI To deploy code from your machine without going through GitHub, run `ployter up` in the project folder. The CLI compresses the folder (without `node_modules`, `.git` and whatever `.gitignore` excludes) and the server builds it as if it came from the repository. ```bash npx @ployter/cli up --project loja --service web ``` The package can be up to 300 MB compressed. If it is larger, check your `.gitignore` or create a `.ployterignore`. This only applies to services with a build (GitHub source) that don't use another service's build. See [CLI](https://ployter.com/en/docs/cli/cli/). ## Build queue on the server Builds compete for the server's memory. Each server has a limit of concurrent builds (the default is 1). Deploys over the limit stay **Queued**, with the reason on the deploy card, and run in the order they arrived. A new request for the same service replaces the one still waiting in the queue. Before each build, if disk space is low, the server clears the build cache. The next build is a little slower, but it doesn't fail for lack of space. ## When the build fails The deploy shows as **Failed** in the **Deploys** tab. Click **View logs** to see the full build output. The panel highlights the BuildKit error line at the top of the deploy. If AI diagnosis is available, the diagnosis button appears next to the error message. See [AI diagnosis](https://ployter.com/en/docs/observability/ai-diagnosis/).