Laravel Go and Rust in containers
Experimental
The container recipes are experimental, and Laravel Go and Laravel Rust are in beta.
laravel_go and laravel_rust deploy a binary run by systemd. To run the application in containers instead, build an image with a multi-stage Containerfile and deploy it with recipes/container: the image is built on your machine for the server platform and streamed over SSH, without registry. The server only needs Docker or Podman.
The Laravel Go and Laravel Rust examples include this setup: Containerfile and deploy.container.ts.
Containerfile
The image builds the assets with Node.js, the binary with Go or Rust, and keeps only what the application needs at runtime.
# Assets: static output, identical for every platform.
FROM docker.io/library/node:24-bookworm-slim AS assets
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build
# Binary: views and migrations are embedded.
FROM docker.io/library/golang:1.27-bookworm AS build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /out/app .
FROM docker.io/library/debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /out/app ./app
COPY --from=assets /app/public ./public
RUN mkdir -p storage && chown -R 1000:1000 storage
USER 1000
# Listen on every interface of the container.
ENV SERVER_HOST=0.0.0.0 SERVER_PORT=8000
EXPOSE 8000
CMD ["./app"]# Assets: static output, identical for every platform.
FROM docker.io/library/node:24-bookworm-slim AS assets
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build
# Binary: migrations are embedded, views are read at runtime.
FROM docker.io/library/rust:1.99-bookworm AS build
WORKDIR /app
COPY . .
RUN cargo build --release --locked && cp target/release/example-app /app/server
FROM docker.io/library/debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /app/server ./server
COPY --from=assets /app/public ./public
COPY resources/views ./resources/views
RUN mkdir -p storage && chown -R 1000:1000 storage
USER 1000
ENV SERVER_HOST=0.0.0.0 SERVER_PORT=8000
EXPOSE 8000
CMD ["./server"]Replace example-app with the name of your Rust package. Add a .dockerignore (and the same .containerignore for Podman) that keeps the build context small and free of secrets:
node_modules
target
.catapult
public/build
.env
storageDeployment
// deploy.ts
import { defineConfig, set } from '@catapultjs/deploy'
import '@catapultjs/deploy/recipes/container'
set('container_project', 'myapp')
set('shared_files', ['.env'])
set('container_services', {
web: {
command: ['./app'],
init: true,
env_file: ['.env'],
ports: ['127.0.0.1:8000:8000'],
},
worker: {
command: ['./app', 'queue:work'],
init: true,
env_file: ['.env'],
},
})
set('container_migrate', { service: 'web', command: ['./app', 'migrate', '--force'] })
export default defineConfig({
hosts: [
{
name: 'production',
ssh: 'deploy@example.com',
deployPath: '/srv/myapp',
healthcheck: { url: 'http://127.0.0.1:8000/up', retries: 10 },
},
],
})With Laravel Rust, use ./server instead of ./app.
- Migrations run in a one-off container of the new image before publication: a failed migration stops the deployment.
- The worker runs the same image with
queue:work, and is recreated on each deployment. shared/.envholds the production settings. Inside a container,127.0.0.1is the container itself: pointDATABASE_URLto a database service, or to the host withoptions: ['--add-host=host.docker.internal:host-gateway']and a database listening on the Docker network.- The scheduler can run as a third service:
command: ['sh', '-c', 'while true; do ./app schedule:run; sleep 60; done'], or as a cron job on the host callingdocker exec.
For zero downtime on the web service behind Caddy, add blue_green to it instead of ports. To run the stack with a database, use recipes/compose with the same Containerfile.
Choosing between the binary and the image
Binary (laravel_go, laravel_rust) | Image (container, compose) | |
|---|---|---|
| Server needs | systemd, and the toolchain for remote builds | Docker or Podman |
| Transfer | binary and assets | whole image, skipped when unchanged |
| Isolation | runs as a system user | container, resource limits, networks |
| Zero downtime | not yet | blue_green behind Caddy |
| Rollback | previous binary | previous image and containers |