Skip to content
Dark blue cover with a DevOps tag, the title DevOps for developers: from laptop to production, and a faint shell prompt symbol in the corner

DevOps for developers: from laptop to production

Table of Contents
  1. Who this guide is for
  2. 1. Reuse one Docker image across environments
  3. 2. Set up a local environment with Docker Compose
  4. 3. Run CI on every merge
  5. 4. Deploy to a single VPS with a reverse proxy and HTTPS
  6. 5. Keep secrets out of the git repo
  7. 6. Back up and restore your data
  8. 7. Secure the server and set up alerts
  9. Applying the same steps to mobile apps
  10. DevOps tools you don’t need yet
  11. What to check first on an existing project
  12. Posts in this series

You can build the app, and the API works on your laptop. What most DevOps advice for developers skips is the path from there to a server that stays up, takes updates without drama and survives a dead disk. For one developer and one small product, that path is short, and you can do it before adding anything bigger.

TL;DR. The 7 steps, in the order I would do them:

  1. Build one Docker image and run it everywhere.
  2. Run the app, PostgreSQL and Redis locally with Docker Compose.
  3. Let CI test, build and push the image on every merge.
  4. Deploy to one VPS behind Caddy, which gets HTTPS certificates automatically.
  5. Keep secrets in .env files on the server and in CI variables, never in git.
  6. Back up the database off-site and restore it at least once.
  7. Harden SSH and the firewall, and watch the service with alerts.

What you’ll learn:

  • what each of the 7 steps protects you from, and which post covers it in depth;
  • the 2 production details that bite most often (Docker bypassing UFW, restores that “fail”);
  • which tools can wait until the product needs them.

Who this guide is for

This guide is for developers who have built an app or an API, know git and have maybe typed docker run once. For an app backend, I recommend Docker Compose on a VPS with Caddy in front, GitLab CI or GitHub Actions, and backups stored with a different provider. The examples use Docker Compose 5.1, Node 24, PostgreSQL 17 and Caddy 2.11. The Node app stands in for whatever you ship. The same Compose and CI files work for a Spring Boot or Django service with a different Dockerfile.

For this blog I use GitLab CI with a self-hosted runner on a small VPS (1 vCPU, 1 GB of RAM). The runner uses the Docker executor and only picks up tagged jobs. The site deploys to Cloudflare Pages with wrangler pages deploy, staging sits behind Cloudflare Access, and a scheduled pipeline runs every day.

That setup costs about 1 USD a month, plus about 12 USD a year for the domain. The first deploy job took around 105 seconds on the runner. A static site is the easy case, though, because there is no database to back up and no app server to keep alive. The rest of this guide is about the harder case.

Pipeline from laptop to production: git push to CI, CI pushes an image tagged with the commit SHA to a registry, the VPS pulls it and runs the app with PostgreSQL behind Caddy with HTTPS, nightly backups go off-site and an uptime monitor sends alerts

1. Reuse one Docker image across environments

A Docker image packages your code with its runtime and dependencies. You build it once, and the same image runs on your laptop, in CI and on the server, so a missing system library shows up on your laptop, not in production.

A multi-stage Dockerfile installs dependencies in one stage and copies only what is needed into the final image:

Dockerfile
# Stage 1: install production dependencies
FROM node:24-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
# Stage 2: the image that runs in production
FROM node:24-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY --from=deps /app/node_modules ./node_modules
COPY server.js ./
USER node
EXPOSE 3000
CMD ["node", "server.js"]
Dockerfile

For this small Node app, the second stage saved almost nothing: the final image was 239 MB, about the size of the node:24-alpine base. The pattern pays off when the build needs heavy tools the runtime does not, such as a JDK and Gradle for a Spring Boot jar, or a compiler for native Python packages (Docker docs on multi-stage builds).

Two habits matter more than the size. Pin base image tags (node:24-alpine, never latest), so a rebuild next month gives you the same runtime. Run as a non-root user (USER node).

2. Set up a local environment with Docker Compose

Compose describes the app and its services in one file, so a new laptop is ready with docker compose up instead of a page of install notes.

compose.yaml
services:
app:
image: demo-app:1.0.0
build: .
environment:
DATABASE_URL: postgres://app:${POSTGRES_PASSWORD}@db:5432/app
ports:
- "127.0.0.1:8080:3000" # loopback only; the reverse proxy is the public door
depends_on:
db:
condition: service_healthy
db:
image: postgres:17-alpine
environment:
POSTGRES_USER: app
POSTGRES_DB: app
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- db-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U app -d app"]
interval: 2s
retries: 15
redis:
image: redis:8.10
volumes:
db-data:
YAML

Compose reads ${POSTGRES_PASSWORD} from a .env file next to compose.yaml. The health check makes the app wait until PostgreSQL accepts connections, instead of crashing on its first query. After docker compose up -d, the health endpoint answers from inside the stack:

Terminal window
$ curl -s localhost:8080/health
{"status":"ok","db":"PostgreSQL 17.12"}
$ docker compose ps --format '{{.Service}} {{.Ports}}'
app 127.0.0.1:8080->3000/tcp
db 5432/tcp
redis 6379/tcp
Bash

Only the app publishes a port, and only on 127.0.0.1. The database and Redis are reachable from other containers by service name (db, redis) and not from the network. Keep that habit in production too; step 7 explains why it matters more than your firewall rules.

3. Run CI on every merge

CI (continuous integration) runs your tests and builds the image on a clean machine every time code lands on the main branch. A green pipeline then becomes the normal way an image gets to the registry, instead of a build from someone’s laptop.

.gitlab-ci.yml
stages: [test, build]
test:
stage: test
image: node:24-alpine
script:
- npm ci
- npm test
build:
stage: build
image: docker:28
services: [docker:28-dind]
variables:
DOCKER_TLS_CERTDIR: "/certs" # dind creates TLS certs; the client reads /certs/client
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY"
- docker build -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA"
YAML

The build job uses Docker-in-Docker (the dind service), which needs a privileged runner. With DOCKER_TLS_CERTDIR set, the dind service generates TLS certificates. The job’s Docker client picks them up from /certs/client. GitLab.com’s shared runners support this as is. On your own runner with the Docker executor, the runner config needs 2 settings (GitLab docs on Docker-in-Docker with TLS):

/etc/gitlab-runner/config.toml (excerpt)
[[runners]]
executor = "docker"
[runners.docker]
privileged = true
volumes = ["/certs/client", "/cache"]
TOML

privileged = true alone is not enough. Without the /certs/client volume, the job never sees the certificates and cannot reach the dind daemon. Keep in mind that a privileged job is effectively root on that machine. I have not run this build job on a real runner. The pipeline file and the runner excerpt are only syntax-checked.

The image tag is the commit SHA, so every deploy maps to one commit and a rollback means deploying the previous tag. A deploy job then connects over SSH and runs IMAGE_TAG=<sha> docker compose -f compose.yaml -f compose.prod.yaml pull, then the same command with up -d (step 4 shows the production file). GitHub Actions does the same with a workflow file and the GitHub container registry (GitLab CI docs, GitHub Actions docs).

Shared runners cost nothing to maintain but come with minute quotas. A self-hosted runner on your own VPS has no quota and keeps build caches warm, but now you patch and secure one more machine. Its jobs also run with access to that machine, so only point it at repositories you trust.

4. Deploy to a single VPS with a reverse proxy and HTTPS

For a small product, one VPS running Compose is enough until real traffic tells you otherwise. In front of the app sits a reverse proxy, the only container that listens on ports 80 and 443 and forwards requests to the app over the Compose network.

I recommend Caddy here because it requests and renews TLS certificates by itself as soon as the domain in the config points at the server (Caddy automatic HTTPS). The whole config for one API is 4 lines:

Caddyfile
api.example.com {
encode zstd gzip
reverse_proxy app:3000
}

On the server, a second Compose file adds Caddy and changes what is different in production:

compose.prod.yaml
services:
caddy:
image: caddy:2.11-alpine
restart: unless-stopped # come back after a reboot
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy-data:/data # certificates live here; keep it across restarts
app:
image: registry.example.com/team/app:${IMAGE_TAG:?set IMAGE_TAG}
restart: unless-stopped
ports: !reset [] # no published port: only Caddy reaches the app
db:
restart: unless-stopped
redis:
restart: unless-stopped
volumes:
caddy-data:
YAML

You start it with docker compose -f compose.yaml -f compose.prod.yaml up -d. The restart lines bring every container back after a reboot, for example after a kernel update. The :? syntax makes a deploy without a tag fail early instead of pulling something unexpected:

Terminal window
$ docker compose -f compose.yaml -f compose.prod.yaml config --quiet
error while interpolating services.app.image: required variable IMAGE_TAG is missing a value: set IMAGE_TAG
Bash

To confirm traffic really goes through the proxy, look for the Via: 1.1 Caddy header in the response, for example with curl -sI https://api.example.com/health.

5. Keep secrets out of the git repo

A secret committed to git stays in the history even after you delete the file, and everyone with clone access has it. Database passwords, API keys and signing keys belong in 2 places only.

On the server, keep them in a .env file that only the deploy user can read, and list .env in .gitignore and .dockerignore:

Terminal window
chmod 600 .env
printf '.env\n' >> .gitignore
printf '.env\n' >> .dockerignore
Bash

Secrets that CI needs, such as the SSH key for the deploy job, go into masked, protected variables (GitLab) or repository secrets (GitHub). If a secret was ever pushed, rotate it. Rewriting history does not undo the leak, because you cannot know who already pulled it.

6. Back up and restore your data

Until you have restored a backup, you do not know whether it works. Dump the database every night with pg_dump, copy the file to storage on a different provider or account, and practise the restore into a fresh database:

Terminal window
docker compose exec -T db pg_dump -U app -d app --format=custom > backups/app-$(date +%F).dump
Bash

I tested it with a table of 1,000 rows. The first restore into a clean postgres:17-alpine container, without extra flags, printed 2 errors and exited with status 1:

Terminal window
$ pg_restore -U postgres -d restore_check < app-2026-11-22.dump
pg_restore: error: could not execute query: ERROR: role "app" does not exist
Command was: ALTER TABLE public.orders OWNER TO app;
...
pg_restore: warning: errors ignored on restore: 2
Bash

The data was all there (select count(*) returned 1000), but a script that trusts the exit code would report a failed restore every night. Adding --no-owner gave exit code 0 and the same 1,000 rows. That is the kind of detail you only find by restoring, so put the restore in a monthly calendar reminder or a scheduled job that checks row counts.

Warning: A backup on the same server as the database dies with that server. Keep at least one copy in another account or provider, and restore from it at least once before you need it.

7. Secure the server and set up alerts

Most of what hits a fresh VPS is automated scanning and password guessing, and the basics block it. Log in with SSH keys only, disable root login and passwords, enable a firewall that allows 22, 80 and 443, and add fail2ban or an equivalent.

Then point an uptime monitor at your health endpoint so you hear about downtime before your users do. Add 2 more alerts, one when the nightly backup job fails and one when a disk passes 80%. Docker’s default json-file log driver does not rotate logs, so set max-size and max-file for it (Docker docs on the json-file driver), or the logs fill the disk eventually.

The firewall has one trap that catches many Docker users. Docker writes its own iptables rules for published ports, and those rules are evaluated before UFW’s, so a port published as "5432:5432" is open to the Internet even when ufw status says it is blocked (Docker docs on packet filtering and firewalls).

The simplest fix lives in the Compose file. Publish only what the proxy needs, and bind everything else to 127.0.0.1 or publish nothing at all, as in steps 2 and 4. Rules in Docker’s DOCKER-USER chain also work, but they are easier to get wrong.

Warning: ufw status does not show ports opened by Docker. Check from outside, for example by running nmap from your laptop against the server, after every change to published ports.

A server I audited in November 2026 had most of these problems at once. Root could log in over SSH with a password, and the log showed 53,620 failed SSH logins in 7 days with no fail2ban. The admin panel of Nginx Proxy Manager was open to the Internet on port 81, one service still had a default admin/admin account, Docker-published ports bypassed UFW, and secrets were committed to git. Steps 5 and 7 above handle almost every item on that list. The default account needs a password change on day one.

Applying the same steps to mobile apps

The same idea applies to Android and iOS builds. CI builds a signed release from a clean checkout, with the keystore or signing certificate stored as a CI secret rather than on one developer’s laptop, then uploads it to the Play Console or TestFlight. The pipeline differs because iOS builds need macOS runners and the store adds its own review step, but the goal does not change. Anyone on the team can ship a release without the one machine that has the keys.

DevOps tools you don’t need yet

Each of these pays off at a size most small products never reach, and the second column says when.

Tool When it pays off Main trade-off
Kubernetes Many services, several servers, a team that can run it You operate a cluster on top of your app
Terraform Infrastructure you recreate often or across environments Another language and state file to manage for a single VPS
Managed container platforms You want no server to patch and accept the price per instance Less control, costs grow with every service
Multi-region Users on several continents or a strict uptime contract Data replication and failover are hard to get right

If you are designing for growth, the system design guide for app developers covers when observability and cost start to drive these choices. Backend developers on the JVM can see where deployment fits in the Java backend roadmap, and Python developers will get a similar map.

What to check first on an existing project

When you take over an existing project, check 2 things before anything else. Has anyone ever restored a backup, and are there secrets in the git history? In my view those 2 are missing most often, and they are the expensive ones when they fail. CI and HTTPS come next, and they are easier to add later.

Posts in this series

  • Writing a production Dockerfile, multi-stage and non-root
  • A local development stack with Docker Compose
  • Choosing a VPS for a small product
  • Deploying with Docker Compose and Caddy
  • Hardening a VPS: lessons from a server audit
  • CI for Android and iOS builds and signing

The first step is the Dockerfile, and it is the next post in this series.

More DevOps posts live in the DevOps category.