[{"content":"Everything I have written so far, newest first.\n","date":null,"permalink":"https://blog.xyzzy.run/posts/","section":"Blog","summary":"","title":"Blog"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/categories/","section":"Categories","summary":"","title":"Categories"},{"content":"I run an OpenClaw node on a Raspberry Pi and the gateway on a server. The node does the work on the robot; the gateway is the long-running service that holds the model credentials and coordinates the nodes. This post is about the server side: a single container, a bind-mounted data directory, and an update path that can be undone.\nThe whole deployment is one Compose service. There is no database container and no orchestration layer. The only state that matters is openclaw-data/, which makes backups and rollbacks much easier than they would be otherwise.\nOpenClaw node(s) │ Tailscale (tailnet) ▼ tailscale serve │ ▼ 127.0.0.1:18789 ──► openclaw container ──► OpenRouter The gateway is published on loopback only. The nodes and the browser UI reach it through Tailscale Serve, which terminates TLS on the tailnet and proxies to 127.0.0.1:18789. The gateway port itself is never published on a public interface.\nThe files #openclaw/ ├── .env ├── .dockerignore ├── Dockerfile ├── docker-compose.yml └── openclaw-data/ # created at runtime The Compose file #services: openclaw: build: . image: openclaw:local container_name: openclaw restart: unless-stopped environment: OPENCLAW_GATEWAY_TOKEN: ${OPENCLAW_GATEWAY_TOKEN} OPENROUTER_API_KEY: ${OPENROUTER_API_KEY} NODE_COMPILE_CACHE: /var/tmp/openclaw-compile-cache OPENCLAW_NO_RESPAWN: \u0026#34;1\u0026#34; ports: - \u0026#34;127.0.0.1:18789:18789\u0026#34; volumes: - ./openclaw-data:/home/node/.openclaw A few decisions are doing most of the work here:\nbuild: . plus image: openclaw:local builds the image locally and gives it a stable name. docker compose build replaces that tag. restart: unless-stopped starts the gateway at boot and restarts it after a crash, but leaves it stopped if you stop it by hand. container_name: openclaw keeps the name stable for docker compose exec, logs, and the rest of the commands below. OPENCLAW_GATEWAY_TOKEN is the shared secret nodes use to authenticate to the gateway. Keep it stable across rebuilds. OPENROUTER_API_KEY is the model-provider credential. It is billed, so it stays in .env and never goes into the image. NODE_COMPILE_CACHE points Node\u0026rsquo;s compile cache at /var/tmp. It speeds up later starts but is only a cache; it does not need to survive a container replacement. OPENCLAW_NO_RESPAWN=1 stops OpenClaw from trying to respawn itself inside the container. Docker\u0026rsquo;s restart policy is the supervisor. 127.0.0.1:18789:18789 publishes the port on host loopback only. This is the most important line in the file. ./openclaw-data:/home/node/.openclaw keeps the gateway\u0026rsquo;s state outside the container. Rebuilding the image does not touch it. The Dockerfile #FROM node:26-trixie-slim # git/curl are needed by some skills and by npm for git-based deps RUN apt-get update \\ \u0026amp;\u0026amp; apt-get install -y --no-install-recommends git curl ca-certificates \\ \u0026amp;\u0026amp; rm -rf /var/lib/apt/lists/* # Install OpenClaw globally RUN npm install -g openclaw@latest # RUN mkdir -p /home/node/.openclaw \u0026amp;\u0026amp; chown -R node:node /home/node/.openclaw RUN mkdir -p \\ /home/node/.openclaw \\ /var/tmp/openclaw-compile-cache \\ \u0026amp;\u0026amp; chown -R node:node \\ /home/node/.openclaw \\ /var/tmp/openclaw-compile-cache # Run as the non-root \u0026#34;node\u0026#34; user that ships with the image USER node WORKDIR /home/node ENV HOME=/home/node EXPOSE 18789 # --bind lan so the port is reachable from outside the container CMD [\u0026#34;openclaw\u0026#34;, \u0026#34;gateway\u0026#34;, \u0026#34;--bind\u0026#34;, \u0026#34;lan\u0026#34;, \u0026#34;--port\u0026#34;, \u0026#34;18789\u0026#34;] The image is deliberately thin. It uses the official Node image, installs the few native tools that skills and npm git dependencies need, installs OpenClaw globally, and then drops to the node user that ships with the base image.\nTwo details are easy to misread:\nEXPOSE 18789 documents the port inside the container. It does not publish anything. The Compose ports mapping is what makes it reachable from the host, and that mapping is loopback-only. --bind lan makes the gateway listen on the container\u0026rsquo;s network interfaces, not just container loopback. That is necessary for the published port to reach it, and it is safe because the host side is bound to 127.0.0.1. npm install -g openclaw@latest means a rebuild can pick up a new release. That is convenient for the update flow below, but it is not reproducible. If you need deterministic rebuilds, pin a version (openclaw@x.y.z) and update the Dockerfile deliberately.\nSecrets and .env #Compose reads a .env file from the project directory automatically. It needs the two values referenced by the Compose file:\nOPENCLAW_GATEWAY_TOKEN=replace-with-a-long-random-token OPENROUTER_API_KEY=replace-with-your-openrouter-key Generate the gateway token with something like:\nopenssl rand -hex 32 Then lock the file down:\nchmod 600 .env Neither value belongs in the Dockerfile, the Compose file, or Git. If the gateway token leaks, rotate it and update the nodes; if the OpenRouter key leaks, revoke it in the OpenRouter dashboard.\nAdd a .gitignore:\n.env openclaw-data/ openclaw-data.bak-* Add a .dockerignore too. The Dockerfile does not COPY the project into the image, but Docker still sends the build context to the daemon. Excluding the data directory and the secrets keeps the context small and keeps credentials out of the daemon\u0026rsquo;s temporary build context:\n.env openclaw-data/ openclaw-data.bak-* .git/ First deploy #cd ~/openclaw # the container runs as UID 1000; make the bind mount writable by that user mkdir -p openclaw-data sudo chown -R 1000:1000 openclaw-data docker compose build docker compose up -d docker compose ps Follow the logs until the gateway reports that it is listening:\ndocker compose logs -f openclaw Ctrl-C stops following the logs; it does not stop the container. In another terminal, check the version and the listening socket:\ndocker compose exec openclaw openclaw --version ss -ltnp | grep 18789 The socket should be 127.0.0.1:18789, not 0.0.0.0:18789. If it is bound to 0.0.0.0, the Compose ports entry or the command-line flags have been changed.\nThe gateway writes into openclaw-data/. The container runs as the node user, which is UID 1000 in the official Node image. If the directory is owned by root and the gateway logs permission errors for /home/node/.openclaw, fix it:\nsudo chown -R 1000:1000 openclaw-data Do this while the container is stopped, or at least before the gateway tries to write again.\nReaching it over Tailscale #The Compose port is loopback-only, so the tailnet cannot reach 18789 directly. Tailscale Serve is the bridge: it listens on the server\u0026rsquo;s tailnet identity, terminates TLS, and proxies to http://127.0.0.1:18789.\nOn the server, with both the server and the nodes joined to the same tailnet:\nsudo tailscale serve --bg 18789 tailscale serve status The output gives a URL like https://server.\u0026lt;tailnet\u0026gt;.ts.net/. That is the address the nodes and the browser use: HTTPS on port 443, with the same gateway token as before. --bg keeps the proxy running in the background. Serve needs HTTPS certificates for the tailnet, which are normally enabled by default; if the command prints a login URL, follow it once.\nTo stop serving:\nsudo tailscale serve --https=443 off Do not use tailscale funnel for this. Funnel publishes the service to the public internet; Serve keeps it inside the tailnet. Tailscale ACLs decide which devices can reach the server, and the OpenClaw gateway token is still required.\nPublishing on the server\u0026rsquo;s Tailscale IP instead (100.x.y.z:18789:18789) would also work, but then TLS and a stable URL are your problem. Keeping the port on loopback and letting Serve handle the tailnet side is the simpler split.\nIf you are on a machine that is not on the tailnet at all, an SSH tunnel still works as a temporary fallback:\nssh -N -L 18789:127.0.0.1:18789 matt@server Then open http://localhost:18789 on your machine. -N keeps the tunnel open without starting a remote shell.\nUpdating #The update is a stop, a backup, a rebuild, and a restart:\ncd ~/openclaw # stop for a consistent backup, then back up with a timestamp docker compose stop TS=$(date +%F-%H%M) cp -a openclaw-data openclaw-data.bak-$TS echo \u0026#34;backup: openclaw-data.bak-$TS\u0026#34; # keep the current image for rollback docker tag openclaw:local openclaw:previous # rebuild and restart docker compose build --no-cache --pull docker compose up -d # verify (Ctrl-C to stop following logs) docker compose exec openclaw openclaw --version docker compose logs -f openclaw A few notes on why the order matters:\ndocker compose stop prevents the gateway from writing while the data directory is copied. That is what makes the backup consistent. cp -a preserves permissions and ownership, which matters because the container runs as UID 1000. docker tag openclaw:local openclaw:previous gives you a one-step rollback. The previous image is overwritten on the next update, so it is not a history. If you want more rollback depth, tag the current image with a date as well: docker tag openclaw:local openclaw:$(date +%F). --no-cache --pull forces a fresh base image and a fresh npm install -g openclaw@latest. Without it, Docker may reuse the cached install layer and you will \u0026ldquo;update\u0026rdquo; to the same version. If the build fails, the old openclaw:local image is still there. Bring it back with docker compose up -d; the service is only stopped, not gone. docker compose logs -f openclaw is the real verification. The version command proves the CLI starts; the logs prove the gateway is listening and has not fallen into a restart loop.\nRolling back #cd ~/openclaw docker compose down # restore the data (only if the new version changed/broke it; otherwise skip these two lines) mv openclaw-data openclaw-data.failed cp -a openclaw-data.bak-\u0026lt;TIMESTAMP\u0026gt; openclaw-data # restore the old image docker tag openclaw:previous openclaw:local docker compose up -d --no-build docker compose down removes the container but leaves the bind-mounted data alone. The openclaw-data.failed directory is deliberate: it preserves the state the new version produced so you can inspect it after the rollback. Do not delete it until the old version has been running long enough to trust.\nOnly restore the backup if the new version migrated or changed the data. If the problem is purely the image, skip the mv/cp lines, retag the old image, and start it again. When in doubt, restore: a working gateway with slightly old state is better than a new gateway with a half-migrated one.\nUpdating a node #The gateway container and the node are separate installations. Rebuilding the container does not update a node. Run this on the machine running the node, as the user that owns that installation:\n# stop the node service so files aren\u0026#39;t replaced under a running process openclaw node stop openclaw update openclaw restart openclaw node stop first is important: openclaw update replaces files, and replacing them under a running process is how you get a half-updated node. openclaw restart brings it back after the CLI has been updated.\nI update the gateway first, then the nodes. They are separate upgrades, so follow whatever order the release notes ask for; the important part is to do them deliberately rather than letting one side drift.\nBackup notes #openclaw-data/ is the only state worth backing up. It contains the gateway\u0026rsquo;s configuration and runtime data, and it may contain credentials. Treat the backups as secrets:\nKeep them outside the Git repository. Encrypt them if they leave the machine. Test a restore before you need it. Prune old backups so a small disk does not fill up silently. For a large data directory, a tarball is easier to move around than a directory copy:\nTS=$(date +%F-%H%M) tar -czf openclaw-data-$TS.tar.gz openclaw-data The docker compose stop step is still worth doing before the tarball.\nTroubleshooting # Symptom Check Container restarts in a loop docker compose logs --tail=100 openclaw. Missing or empty env vars, a bad token, or a data-directory permission error are the usual causes. EACCES on /home/node/.openclaw The bind mount is not writable by UID 1000. Stop the container and sudo chown -R 1000:1000 openclaw-data. bind: address already in use Something else owns 18789 on the host. ss -ltnp | grep 18789, then change the host side of the mapping (for example 127.0.0.1:18790:18789). Cannot reach the gateway from another machine Expected. The port is loopback-only. Check tailscale serve status and use the Serve URL from a tailnet device; use an SSH tunnel from a machine outside the tailnet. docker compose build fails It needs network access to pull the base image and to run npm install. Check git/curl/CA certificates in the image and the build output. The old image is still available. docker compose exec says the service is not running docker compose ps first. exec only works on a running container; use run --rm for a one-off command. .env changes have no effect Compose only reads .env from the project directory, and the file needs KEY=value with no spaces around =. Re-run docker compose up -d after changing it. The rollback image starts but the gateway errors on data The new version changed the data format. Repeat the rollback and restore the matching openclaw-data.bak-*. Wrapping up #The deployment is small on purpose: one service, one bind mount, two secrets, and a loopback-only port. The container is disposable; openclaw-data/ is the part that matters. Once that division is clear, updates and rollbacks are just \u0026ldquo;stop, copy, retag, rebuild\u0026rdquo; and \u0026ldquo;retag, restore, start\u0026rdquo;.\nThat is also why the backup is taken before the build, not after: the point is to have a known-good copy of the state from before the new image ever touched it.\n","date":"29 November 2026","permalink":"https://blog.xyzzy.run/posts/openclaw-docker-server/","section":"Blog","summary":"Run the OpenClaw gateway with Docker Compose, keep its state on a bind mount, and update or roll back without losing data.","title":"Deploying OpenClaw in a Container on a Server"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/docker/","section":"Tags","summary":"","title":"Docker"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/categories/infrastructure/","section":"Categories","summary":"","title":"Infrastructure"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/linux/","section":"Tags","summary":"","title":"Linux"},{"content":"Welcome. This is where I write up the things I build, break, and fix — mostly Raspberry Pi projects, embedded hardware, Linux setup notes, and whatever else seems worth writing down.\nRecent posts cover pairing an Xbox controller directly with a Raspberry Pi over Bluetooth, setting up a C++ development environment on Linux with VS Code, CMake, and vcpkg, running the OpenClaw gateway in a container, and serving apps with Caddy and automatic HTTPS.\n","date":null,"permalink":"https://blog.xyzzy.run/","section":"Notes from the workshop","summary":"","title":"Notes from the workshop"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/openclaw/","section":"Tags","summary":"","title":"OpenClaw"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/self-hosting/","section":"Tags","summary":"","title":"Self-Hosting"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/","section":"Tags","summary":"","title":"Tags"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/caddy/","section":"Tags","summary":"","title":"Caddy"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/https/","section":"Tags","summary":"","title":"HTTPS"},{"content":"The server has one job: run apps and serve them over HTTPS. The shape I ended up with is simple. Caddy is the only container with published ports. Every app lives on a private Docker network, listens on an internal port, and is reachable only through Caddy. Caddy gets the certificates, renews them, redirects HTTP to HTTPS, and proxies the requests.\nInternet :80/:443 │ ▼ caddy container TLS + reverse proxy │ web network ├── go-app:8080 └── another-app:3000 There is no certbot, no cron job, and no per-app TLS configuration. Adding an app means adding a service, adding a site block to the Caddyfile, and pointing DNS at the server.\nThe examples use example.com and a generic Go app called go-app; replace those with your own domain and service name.\nBefore the stack #The server is a Debian/Ubuntu box with a public IPv4 address. You need:\nA domain you control, with DNS records pointing at the server. Docker Engine and the Compose plugin. Verify with docker compose version. A user in the docker group, or sudo for every command. ufw if you want the host firewall in front of the published ports. Install Docker from the official Engine instructions rather than from a distribution package that may be years behind. Then add your user to the docker group and log in again:\nsudo usermod -aG docker \u0026#34;$USER\u0026#34; DNS first #Caddy can only get a certificate for a name that resolves to the server. Point an A record at the IPv4 address for every hostname in the Caddyfile:\nexample.com A 203.0.113.10 www.example.com A 203.0.113.10 app.example.com A 203.0.113.10 If the server has IPv6, add matching AAAA records and make sure the firewall allows 80 and 443 over IPv6 too. Check propagation from the server:\ndig +short example.com dig +short app.example.com If dig is not installed, it is in the dnsutils package:\nsudo apt install -y dnsutils Do this before starting Caddy. Caddy will retry failed certificate requests, but it is much easier to debug DNS first than to read ACME errors in the logs.\nFirewall #The host firewall allows SSH on a non-default port, plus the two ports Caddy needs. The order matters: allow the new SSH port before denying the old one, and keep the current session open while you test.\nsudo ufw default deny incoming sudo ufw default allow outgoing # SSH on 2233; substitute your own port sudo ufw allow 2233/tcp # Caddy sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw allow 443/udp # only after confirming 2233 works sudo ufw deny 22/tcp sudo ufw enable sudo ufw status verbose The resulting rules should look like this:\nTo Action From -- ------ ---- 2233/tcp ALLOW IN Anywhere 80/tcp ALLOW IN Anywhere 443/tcp ALLOW IN Anywhere 443/udp ALLOW IN Anywhere 22/tcp DENY IN Anywhere 80 is needed for the ACME HTTP challenge and for the HTTP-to-HTTPS redirect. 443 is the actual TLS listener. 443/udp enables HTTP/3; if you do not want it, drop that rule and the corresponding Compose port.\nThe SSH change is not security by itself. It cuts log noise, but the real protection is key-only authentication, no root login, and keeping the host patched. Changing the firewall rule does not move sshd: set Port 2233 in /etc/ssh/sshd_config (or a drop-in), restart SSH, and test a second session on 2233 before closing the one you have. If you previously allowed port 22, remove that rule before adding the deny:\nsudo ufw delete allow 22/tcp sudo ufw delete allow OpenSSH sudo ufw deny 22/tcp Docker and UFW: Docker publishes container ports by writing its own iptables rules, and those can bypass UFW. That is one reason the app containers here use expose instead of ports. If you publish an app port, do not assume UFW is protecting it. Only Caddy gets a host port.\nIf the server is at a cloud provider, open 80 and 443 in the provider\u0026rsquo;s firewall or security group as well. The host firewall is only one layer.\nRepository layout #I keep the infrastructure repository at /opt/myserver, with the app next to the Compose file:\n/opt/myserver/ ├── caddy/ │ └── Caddyfile ├── docker-compose.yml ├── README.md └── go-app/ ├── Dockerfile ├── env.sample ├── go.mod ├── main.go └── static/ The infra repo owns the public surface: the Caddyfile, the Compose file, and the network. The app repo owns the application and its Dockerfile. Clone the infra repo into place and give your user ownership:\nsudo mkdir -p /opt/myserver sudo chown \u0026#34;$USER\u0026#34;:\u0026#34;$USER\u0026#34; /opt/myserver git clone git@github.com:you/infra.git /opt/myserver cd /opt/myserver go-app/ is either a Git submodule of the infra repo or a separate checkout. If it is a submodule:\ngit submodule update --init --recursive If it is a separate repository, clone it into place:\ngit clone git@github.com:you/go-app.git /opt/myserver/go-app Create the app\u0026rsquo;s environment file from the sample and keep it out of Git:\ncp go-app/env.sample go-app/.env chmod 600 go-app/.env $EDITOR go-app/.env Add the usual ignores to the infra repository:\ngo-app/.env **/.env The Compose file #services: caddy: image: caddy:2 container_name: caddy restart: unless-stopped ports: - \u0026#34;80:80\u0026#34; - \u0026#34;443:443\u0026#34; - \u0026#34;443:443/udp\u0026#34; volumes: - ./caddy/Caddyfile:/etc/caddy/Caddyfile:ro - caddy_data:/data - caddy_config:/config networks: - web go-app: build: context: ./go-app container_name: go-app env_file: - ./go-app/.env restart: unless-stopped expose: - \u0026#34;8080\u0026#34; networks: - web volumes: caddy_data: caddy_config: networks: web: driver: bridge The important details:\nCaddy publishes 80, 443, and 443/udp. It is the only public listener. caddy_data stores Caddy\u0026rsquo;s certificates, account keys, and ACME state. Do not delete it unless you want Caddy to start over. caddy_config stores Caddy\u0026rsquo;s autosaved config. Keep it with the data volume. The Caddyfile is mounted read-only. Edit it on the host, then reload Caddy. go-app uses expose, not ports. It is reachable as go-app:8080 on the web network, but not from the host or the internet. Caddy reaches the app by its Compose service name. Docker\u0026rsquo;s DNS resolves go-app inside the web network. The app must listen on 0.0.0.0:8080 inside its container. If it binds 127.0.0.1:8080, Caddy will get a connection refused and return 502. container_name is convenient for logs and docker compose exec, but it makes the service harder to scale. For one server with one copy of each app, it is fine.\nThe Caddyfile #example.com app.example.com { reverse_proxy go-app:8080 } www.example.com { redir https://example.com{uri} permanent } The first block serves the same app on both example.com and app.example.com. Caddy provisions a certificate for every hostname in the block, so both names must resolve to the server.\nreverse_proxy go-app:8080 sends requests to the app container over the web network. Caddy adds the usual forwarding headers and handles WebSocket upgrades, so an app that uses WebSockets or streaming responses does not need extra proxy configuration.\nThe www block is a canonical redirect. Caddy\u0026rsquo;s automatic HTTPS already redirects http:// to https://; this block handles the hostname change. If you do not want www, remove the block and the DNS record.\nIf you want to give the ACME account an email address, put a global options block at the top:\n{ email you@example.com } It is optional, but it gives the certificate authority a contact address and makes expiry notices possible.\nCaddy stores the certificates under /data. The named volume is what keeps them across container restarts and rebuilds. Without it, every recreate would request new certificates, which is a good way to hit rate limits.\nFirst deploy #cd /opt/myserver docker compose up -d --build docker compose ps Watch Caddy\u0026rsquo;s logs while it obtains certificates:\ndocker compose logs -f caddy Look for a certificate obtained or serving message. The first request can take a few seconds while ACME completes. Then check the app logs:\ndocker compose logs -f go-app From outside the server, verify the three paths:\ncurl -I http://example.com curl -I https://example.com curl -I https://www.example.com curl -I https://app.example.com The HTTP request should redirect to HTTPS (308 is Caddy\u0026rsquo;s automatic redirect). The www request should redirect to the apex domain (301 from the Caddyfile). The HTTPS requests should return whatever the app returns, usually 200 or a redirect to a login page.\nIf https:// works but http:// times out, port 80 is blocked somewhere. If the certificate request never completes, check DNS and ports 80/443 before changing the Caddyfile.\nHow the TLS part works #Caddy\u0026rsquo;s automatic HTTPS does the certificate work:\nIt obtains a certificate for each site address from an ACME CA, usually Let\u0026rsquo;s Encrypt or ZeroSSL. It completes the HTTP-01 or TLS-ALPN-01 challenge on ports 80 and 443. It renews certificates before they expire and reloads them without a restart. It redirects HTTP to HTTPS automatically. There is no certbot timer to maintain and no certificate files to copy into the app. The app only ever speaks plain HTTP on the private Docker network; Caddy is the TLS endpoint.\nCaddy will not issue a public certificate for localhost, a bare IP address, or a name that does not resolve publicly. If you are testing locally, use a real domain or Caddy\u0026rsquo;s internal CA, not the public ACME flow.\nIf you put Cloudflare or another proxy in front of the server, either set the records to DNS-only so the ACME challenge reaches the server, or configure Caddy\u0026rsquo;s DNS challenge. An orange-cloud proxy that hides the origin can break HTTP-01.\nAdding another app #Add a service to the Compose file:\nanother-app: build: context: ./another-app container_name: another-app restart: unless-stopped expose: - \u0026#34;3000\u0026#34; networks: - web Add a site block to the Caddyfile:\nanother.example.com { reverse_proxy another-app:3000 } Point another.example.com at the server, rebuild, and reload Caddy. The app does not get a host port; Caddy is still the only public listener.\nThe contract is the same every time: the app listens on 0.0.0.0:\u0026lt;port\u0026gt;, the service name and port match the reverse_proxy target, and both containers are on the web network.\nApplying Caddyfile changes #A Caddyfile edit is a bind-mount content change, so docker compose up -d will not recreate the Caddy container by itself. Validate and reload it:\ndocker compose exec caddy caddy validate --config /etc/caddy/Caddyfile docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile caddy reload is graceful and keeps the old config if the new one is invalid. If you prefer a bigger hammer, docker compose restart caddy also re-reads the file, at the cost of a brief interruption.\nCheck the logs after a reload. A syntax error or an unresolvable hostname will show up there immediately.\nUpdating an app #The update flow is intentionally short:\ncd /opt/myserver/go-app git pull cd .. docker compose up -d --build docker compose up -d --build rebuilds the app image and recreates the app container if the image changed. Caddy is not rebuilt, its certificates are untouched, and the public listener stays up. The app will be unavailable for the moment it takes to recreate the container; Caddy returns 502 during that window.\nFor an infra change, pull the infra repo first:\ncd /opt/myserver git pull docker compose up -d --build If the Caddyfile changed, run the validate/reload commands above.\nPrivate GitHub repositories #For a private app repo, use a read-only SSH deploy key on the server rather than a personal access token in the clone URL. Generate a key that is specific to this server and repository:\nssh-keygen -t ed25519 -C \u0026#34;server-deploy\u0026#34; -f ~/.ssh/go-app-deploy -N \u0026#34;\u0026#34; cat ~/.ssh/go-app-deploy.pub Add the public key to the repository under Settings → Deploy keys, with write access disabled. Then point the remote at SSH. If the server has multiple GitHub keys, use a host alias:\nHost github.com-go-app HostName github.com User git IdentityFile ~/.ssh/go-app-deploy IdentitiesOnly yes git remote set-url origin git@github.com-go-app:owner/go-app.git ssh -T git@github.com-go-app git pull If the key is lost, revoke it in the repository settings and generate a new one. Do not copy the private key into the image, the Compose file, or the repository.\nTroubleshooting # Symptom Check Caddy cannot obtain a certificate DNS for every hostname in the site block, ports 80/443 from outside, IPv6 rules, and the Caddy logs. A proxied CDN record can also block HTTP-01. HTTPS returns 502 Bad Gateway The app is not listening on 0.0.0.0:\u0026lt;port\u0026gt;, the service name/port in reverse_proxy is wrong, or the app is not on the web network. Check docker compose logs go-app. http:// does not redirect Port 80 is blocked, or Caddy is not running. Check sudo ufw status and the provider firewall. Caddyfile changes do nothing docker compose up -d does not recreate Caddy for a bind-mount content change. Run caddy reload or restart the container. www redirects in a loop Do not both reverse-proxy and redirect the same hostname. Keep www only in the redirect block. Certificate rate limit Recreating Caddy repeatedly with an empty /data volume requests new certificates. Keep caddy_data and use the ACME staging CA while testing. .env changes are ignored The app reads its environment at container start. Recreate the app container with docker compose up -d after editing the file. Docker published an app port anyway Check for a ports: entry on the app service. Use expose and let Caddy proxy it. UFW may not filter Docker-published ports. Wrapping up #The setup is one public listener, one private network, and one place where TLS lives. DNS and the firewall are the only host-level pieces; after that, Caddy and Compose do the repetitive work.\nAdding an app is a service block, a Caddyfile block, and a DNS record. Updating an app is git pull and docker compose up -d --build. Certificate renewal is not a task at all — it is part of Caddy\u0026rsquo;s normal operation.\n","date":"24 November 2026","permalink":"https://blog.xyzzy.run/posts/caddy-server-https/","section":"Blog","summary":"Use Caddy as the only public listener, reverse-proxy Docker apps over a private network, and let Caddy handle TLS, redirects, and renewals.","title":"Serving Apps with Automatic HTTPS on a Small Server"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/bluetooth/","section":"Tags","summary":"","title":"Bluetooth"},{"content":"An Xbox controller is just a Bluetooth HID device, so a Raspberry Pi with Bluetooth can talk to one directly — no dongle, no wireless receiver, and no extra driver package. That makes the controller a good fit for a robot, a media centre, or anything else where reaching for a keyboard is awkward.\nI paired an Xbox One S controller with a Raspberry Pi 3B running 64-bit Raspberry Pi OS. It worked, but only after a few BlueZ tweaks; the default settings dropped the connection often enough to be useless. This is the sequence that ended up being reliable.\nThese instructions are for controllers with Bluetooth: Xbox One S, Xbox One X, Xbox Series X|S, and Xbox Elite Series 2. The original Xbox One controller and Xbox 360 controllers are not Bluetooth and need their own USB receiver. What you need # A Raspberry Pi with Bluetooth (onboard, or a supported USB Bluetooth adapter) running Raspberry Pi OS. A Bluetooth-capable Xbox controller with charged batteries. A terminal on the Pi, either locally or over SSH, and sudo access. Start by checking that the adapter exists and is not blocked:\nrfkill list bluetooth If Bluetooth is soft-blocked, unblock it:\nsudo rfkill unblock bluetooth Then check that BlueZ sees a powered adapter:\nbluetoothctl show Powered: yes is what you want. If it says no, run bluetoothctl power on.\n1. Install the tools #Raspberry Pi OS usually has Bluetooth and BlueZ installed already. The two packages worth adding are evtest and joystick, which provide evtest and jstest for checking that the controller actually produces input:\nsudo apt update sudo apt install -y bluetooth bluez evtest joystick 2. Disable ERTM #ERTM (Enhanced Retransmission Mode) is a Bluetooth reliability feature that Xbox controllers handle badly on Linux. The usual symptom is a controller that pairs, works for a few seconds, then stutters or disconnects. Disable it for the running kernel:\necho 1 | sudo tee /sys/module/bluetooth/parameters/disable_ertm sudo systemctl restart bluetooth This setting is not persistent. To apply it at every boot, add a module option and reboot:\necho \u0026#39;options bluetooth disable_ertm=1\u0026#39; | sudo tee /etc/modprobe.d/bluetooth.conf sudo reboot After the reboot, cat /sys/module/bluetooth/parameters/disable_ertm should show Y. If it still shows N, the option did not take effect — check that the Bluetooth driver is built as a module on your kernel.\n3. Relax the input rules in BlueZ #BlueZ has a separate configuration file for HID devices. Open /etc/bluetooth/input.conf:\nsudo nano /etc/bluetooth/input.conf Set these keys under [General]:\n[General] UserspaceHID=true ClassicBondedOnly=false LEAutoSecurity=false What each one does:\nUserspaceHID=true handles HID in BlueZ\u0026rsquo;s userspace process (via UHID) instead of the kernel\u0026rsquo;s HIDP module. This is the mode that tends to behave best with the Xbox controller. ClassicBondedOnly=false lets a device connect before a full bond exists. The default is true, which can reject the controller during its just-works pairing. LEAutoSecurity=false disables automatic LE security upgrades. The controller is bonded explicitly with pair below, so BlueZ does not need to try to upgrade the connection on its own. These settings are deliberately permissive. They are fine on a Pi on your own network, but do not treat Bluetooth pairing as a security boundary: a nearby device can attempt a connection with these defaults relaxed.\n4. Tune the Bluetooth adapter #Now edit /etc/bluetooth/main.conf:\nsudo nano /etc/bluetooth/main.conf Merge these keys into the existing [General] section. Do not add a second [General] header if one is already there:\n[General] Privacy = device JustWorksRepairing = always ControllerMode = dual [LE] MinConnectionInterval = 7 MaxConnectionInterval = 9 ConnectionLatency = 0 ConnectionSupervisionTimeout = 200 Why these values:\nControllerMode = dual lets the adapter run both Bluetooth Classic and LE. If it was set to bredr or le only, the controller may pair but never connect. Privacy = device enables LE private addresses while still accepting a peer\u0026rsquo;s identity address, which is what lets a bonded controller reconnect. JustWorksRepairing = always allows a device to pair again without deleting the old bond first. It needs BlueZ 5.55 or newer. The [LE] values ask for a short connection interval (7–9 units of 1.25 ms) and a 2-second supervision timeout. That trades a little power for a more responsive pad. If your controller connects over Classic instead of LE, these keys are simply ignored. Restart Bluetooth to apply both files:\nsudo systemctl restart bluetooth 5. Put the controller in pairing mode #Turn the controller on with the Xbox button. Then hold the small pairing button until the Xbox logo flashes quickly. On an Xbox One S the button is on the top edge next to the USB port; on a Series controller it is on the top edge near the USB-C port. Slow blinking means the controller is on but not advertising; fast blinking means it is in pairing mode.\nIf the controller was previously paired with a console or phone, turn that device off or remove the controller from it first. Otherwise the controller may reconnect to the old host instead of the Pi.\n6. Pair, trust, and connect #Start the BlueZ shell:\nbluetoothctl Inside it, turn the adapter on and scan:\npower on agent on default-agent scan on Wait for a line like this to appear:\n[NEW] Device XX:XX:XX:XX:XX:XX Xbox Wireless Controller That address is the controller\u0026rsquo;s MAC address; use yours everywhere below. Stop the scan and pair:\nscan off remove XX:XX:XX:XX:XX:XX pair XX:XX:XX:XX:XX:XX trust XX:XX:XX:XX:XX:XX connect XX:XX:XX:XX:XX:XX quit A few notes on the order:\nremove clears any stale bond from an earlier attempt. If it reports Device not available, that is fine — there was nothing to remove. pair performs the just-works pairing. There is no PIN to enter. trust lets the controller reconnect automatically in future. connect opens the connection now. The Xbox logo should stay solid when it succeeds. 7. Verify that input arrives #First check that the kernel created a joystick device:\nls /dev/input/js* Then list the input devices and look for the controller:\ncat /proc/bus/input/devices | grep -A 8 -i xbox The most direct test is evtest:\nsudo evtest Pick the event device whose name contains Xbox Wireless Controller, then move the sticks and press the buttons. You should see a stream of events. If you prefer an axis/button view, use jstest:\nsudo jstest /dev/input/js0 If /dev/input/js0 does not exist but evtest sees the controller, load the joystick compatibility module:\nsudo modprobe joydev At this point the controller is connected directly to the Pi and can be read by any joystick-aware program. In Python, for example, pygame.joystick will see it as joystick 0. On a headless Pi, set the dummy SDL video driver before importing pygame:\nimport os os.environ.setdefault(\u0026#34;SDL_VIDEODRIVER\u0026#34;, \u0026#34;dummy\u0026#34;) import pygame pygame.init() pygame.joystick.init() pad = pygame.joystick.Joystick(0) pad.init() print(pad.get_name()) Reconnecting later #Once the controller is trusted, pressing the Xbox button should reconnect it automatically. If it does not, connect it explicitly:\nbluetoothctl connect XX:XX:XX:XX:XX:XX After a reboot, give the Bluetooth service a moment to start, then press the Xbox button. If the controller still will not connect, check systemctl status bluetooth and run through the troubleshooting steps below.\nTroubleshooting # Symptom Things to check Controller never appears in scan on Is it actually in pairing mode (fast flash)? Are the batteries good? Is it still connected to a console or phone? Failed to connect: org.bluez.Error.Failed Restart Bluetooth, remove the old bond, and pair again. journalctl -u bluetooth -b usually says why. Pairs, then disconnects after a few seconds ERTM has not been disabled, or the BlueZ config was not reloaded. Re-run the disable_ertm command and restart Bluetooth. Connects but input is laggy Disable ERTM, move the Pi away from 2.4 GHz congestion, and check the [LE] interval values. Ethernet or 5 GHz Wi-Fi helps. No /dev/input/js* evtest still sees it? Load joydev as above. Otherwise check dmesg for the input device. Works once, then refuses after a config change Delete the bond with remove, then pair, trust, and connect again. The remove-then-repair cycle is the fix for most BlueZ weirdness. If you change input.conf or main.conf, do that before assuming the controller is at fault.\nWrapping up #That is the whole setup: disable ERTM, relax the HID rules, set the adapter to dual mode with a short LE interval, then pair and trust the controller. After that it behaves like any other joystick on the Pi — no receiver, no dongle, and no extra service to keep running.\nOn the PiCar-X I use this with, the left stick steers, the triggers drive, and the right stick aims the camera. The same pairing steps work for any program that reads a joystick, so the controller is not tied to the robot.\n","date":"22 November 2026","permalink":"https://blog.xyzzy.run/posts/connect-xbox-controller-raspberry-pi/","section":"Blog","summary":"Pair an Xbox One or Series controller with a Raspberry Pi over Bluetooth, including the BlueZ settings that keep it connected.","title":"Connecting an Xbox Controller Directly to a Raspberry Pi"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/categories/hardware/","section":"Categories","summary":"","title":"Hardware"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/raspberry-pi/","section":"Tags","summary":"","title":"Raspberry Pi"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/xbox/","section":"Tags","summary":"","title":"Xbox"},{"content":"VS Code\u0026rsquo;s Using C++ on Linux tutorial is a good way to get a single helloworld.cpp compiling with g++ and debugging with GDB. The moment a project grows past one file, though, the hand-written tasks.json arguments and the include list in c_cpp_properties.json become a second project to maintain.\nThis is the setup I use instead: CMake owns the build, vcpkg owns third-party dependencies, and the CMake Tools and C/C++ extensions connect the two. You get IntelliSense from the real compile flags, one-key builds, and GDB debugging without maintaining compiler arguments or include paths by hand.\nThe stack # Piece What it does VS Code Editor and debugger front end. C/C++ extension IntelliSense, navigation, and GDB integration. CMake Tools extension Configure, build, test, and debug targets from the editor. CMake + Ninja Generates and runs the build. vcpkg Installs the libraries the project declares. GCC + GDB Compiles the code and debugs the binary. The important idea is that CMake is the single source of truth. VS Code does not get its own list of compiler flags or include directories; it asks CMake Tools, which asks CMake. When a dependency is added, both the build and IntelliSense see it.\n1. Install the native toolchain #The commands below assume a Debian or Ubuntu based distribution. Adjust the package names for Fedora, Arch, or whatever you run.\nsudo apt update sudo apt install -y \\ build-essential \\ gdb \\ cmake \\ ninja-build \\ git \\ curl \\ zip \\ unzip \\ tar \\ pkg-config Some vcpkg ports run autoconf, automake, libtool, bison, or flex during their build. Install those now so a dependency does not fail halfway through:\nsudo apt install -y autoconf automake libtool bison flex python3 perl Check that everything is on PATH:\ng++ --version cmake --version ninja --version gdb --version CMake 3.21 or newer is enough for the presets below. The CMake Tools extension recommends 3.27 or newer; Ubuntu 24.04 and Debian 13 ship a version that is new enough. If your distribution is older, the Kitware APT repository has current packages.\n2. Install vcpkg #I keep one vcpkg checkout in /opt/vcpkg and share it between projects. The directory has to be writable by your user because vcpkg updates its own registry and downloads sources there:\nsudo mkdir -p /opt/vcpkg sudo chown \u0026#34;$USER\u0026#34;:\u0026#34;$USER\u0026#34; /opt/vcpkg git clone https://github.com/microsoft/vcpkg.git /opt/vcpkg /opt/vcpkg/bootstrap-vcpkg.sh -disableMetrics If you would rather not use sudo, ~/vcpkg works just as well; the only thing that changes is the value of VCPKG_ROOT.\nRun the bootstrap script as yourself, not with sudo. Running it as root leaves root-owned files behind and the next vcpkg command will fail with a permission error. If you already did that, fix it with:\nsudo chown -R \u0026#34;$USER\u0026#34;:\u0026#34;$USER\u0026#34; /opt/vcpkg -disableMetrics opts out of vcpkg\u0026rsquo;s telemetry. Drop it if you want to keep telemetry enabled. Now put the checkout on your PATH and export VCPKG_ROOT. Add this to ~/.bashrc or ~/.zshrc:\nexport VCPKG_ROOT=\u0026#34;/opt/vcpkg\u0026#34; export PATH=\u0026#34;$VCPKG_ROOT:$PATH\u0026#34; Reload the shell and check:\nsource ~/.bashrc # or: source ~/.zshrc vcpkg version echo \u0026#34;$VCPKG_ROOT\u0026#34; VCPKG_ROOT matters more than the PATH entry: the CMake toolchain file lives at $VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake, and that is how CMake finds the packages vcpkg installs.\nA VS Code gotcha: a VS Code window launched from the desktop icon may not inherit exports from ~/.bashrc. Open the project with code . from a terminal, or put the exports in ~/.profile (or ~/.config/environment.d/vcpkg.conf) so the graphical session sees them. Restart VS Code after changing the environment; an already-running window keeps its old environment.\n3. Create the project and its manifest #mkdir -p ~/dev/hello-vcpkg cd ~/dev/hello-vcpkg Inside the project, create a vcpkg manifest and add fmt as a dependency:\nvcpkg new --application vcpkg add port fmt vcpkg new --application creates two files:\nvcpkg.json — the manifest that lists this project\u0026rsquo;s dependencies. vcpkg-configuration.json — the registry and baseline information that pins the versions vcpkg resolves. Then vcpkg add port fmt edits the manifest. It should look like this:\n{ \u0026#34;name\u0026#34;: \u0026#34;hello-vcpkg\u0026#34;, \u0026#34;version-string\u0026#34;: \u0026#34;0.1.0\u0026#34;, \u0026#34;dependencies\u0026#34;: [ \u0026#34;fmt\u0026#34; ] } The name comes from the directory, so yours may differ. This is manifest mode: dependencies are declared per project instead of being installed globally. That is what makes the setup reproducible for the next person, or for future you on a new machine.\nKeep both JSON files under source control. vcpkg-configuration.json is what keeps the dependency versions from drifting.\n4. Add the CMake project #Create CMakeLists.txt:\ncmake_minimum_required(VERSION 3.21) project(hello_vcpkg VERSION 0.1.0 DESCRIPTION \u0026#34;VS Code + CMake + vcpkg demo\u0026#34; LANGUAGES CXX ) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) find_package(fmt CONFIG REQUIRED) add_executable(hello main.cpp) target_link_libraries(hello PRIVATE fmt::fmt) target_compile_options(hello PRIVATE -Wall -Wextra -Wpedantic) find_package(fmt CONFIG REQUIRED) is the line vcpkg makes possible. The fmt::fmt target carries the include directories, compile definitions, and link libraries that fmt needs. There is no -I or -L to maintain.\nAdd main.cpp:\n#include \u0026lt;fmt/core.h\u0026gt; #include \u0026lt;string\u0026gt; int main() { const std::string name = \u0026#34;vcpkg\u0026#34;; fmt::print(\u0026#34;Hello, {}!\\n\u0026#34;, name); return 0; } Then add CMakePresets.json at the project root:\n{ \u0026#34;version\u0026#34;: 3, \u0026#34;cmakeMinimumRequired\u0026#34;: { \u0026#34;major\u0026#34;: 3, \u0026#34;minor\u0026#34;: 21, \u0026#34;patch\u0026#34;: 0 }, \u0026#34;configurePresets\u0026#34;: [ { \u0026#34;name\u0026#34;: \u0026#34;base\u0026#34;, \u0026#34;hidden\u0026#34;: true, \u0026#34;generator\u0026#34;: \u0026#34;Ninja\u0026#34;, \u0026#34;binaryDir\u0026#34;: \u0026#34;${sourceDir}/build/${presetName}\u0026#34;, \u0026#34;cacheVariables\u0026#34;: { \u0026#34;CMAKE_TOOLCHAIN_FILE\u0026#34;: { \u0026#34;value\u0026#34;: \u0026#34;$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake\u0026#34;, \u0026#34;type\u0026#34;: \u0026#34;FILEPATH\u0026#34; }, \u0026#34;CMAKE_EXPORT_COMPILE_COMMANDS\u0026#34;: \u0026#34;ON\u0026#34; } }, { \u0026#34;name\u0026#34;: \u0026#34;debug\u0026#34;, \u0026#34;displayName\u0026#34;: \u0026#34;Debug\u0026#34;, \u0026#34;inherits\u0026#34;: \u0026#34;base\u0026#34;, \u0026#34;cacheVariables\u0026#34;: { \u0026#34;CMAKE_BUILD_TYPE\u0026#34;: \u0026#34;Debug\u0026#34; } }, { \u0026#34;name\u0026#34;: \u0026#34;release\u0026#34;, \u0026#34;displayName\u0026#34;: \u0026#34;Release\u0026#34;, \u0026#34;inherits\u0026#34;: \u0026#34;base\u0026#34;, \u0026#34;cacheVariables\u0026#34;: { \u0026#34;CMAKE_BUILD_TYPE\u0026#34;: \u0026#34;Release\u0026#34; } } ], \u0026#34;buildPresets\u0026#34;: [ { \u0026#34;name\u0026#34;: \u0026#34;debug\u0026#34;, \u0026#34;configurePreset\u0026#34;: \u0026#34;debug\u0026#34; }, { \u0026#34;name\u0026#34;: \u0026#34;release\u0026#34;, \u0026#34;configurePreset\u0026#34;: \u0026#34;release\u0026#34; } ] } The base preset is hidden and holds the shared settings. debug and release inherit it and only change CMAKE_BUILD_TYPE, which keeps the two builds from sharing a cache by using build/debug and build/release.\nWhy the important fields are there:\ngenerator: Ninja is fast and has good dependency tracking. binaryDir keeps generated files out of the source tree. CMAKE_TOOLCHAIN_FILE is the bridge to vcpkg. It has to be set when CMake first configures the project. CMAKE_EXPORT_COMPILE_COMMANDS writes a compile_commands.json file, which is useful for clangd and other tools. The C/C++ extension gets its information from CMake Tools instead, but the file costs nothing. At this point the project looks like this:\nhello-vcpkg/ ├── CMakeLists.txt ├── CMakePresets.json ├── main.cpp ├── vcpkg-configuration.json └── vcpkg.json 5. Build from the terminal first #Before involving VS Code, prove the build works:\ncmake --preset debug cmake --build --preset debug ./build/debug/hello You should see:\nHello, vcpkg! The first configure takes a while. CMake invokes vcpkg, vcpkg reads vcpkg.json, downloads the fmt sources, builds them, and installs them under build/debug/vcpkg_installed. Later configures reuse the binary cache in ~/.cache/vcpkg/archives and are much faster.\nIf this step fails, fix it here. Debugging CMake through the editor before the command line works just adds a layer of indirection.\n6. Configure VS Code #Install the two extensions, either from the Extensions view or from the command line:\ncode --install-extension ms-vscode.cpptools code --install-extension ms-vscode.cmake-tools If code is not on your PATH, install the same two extensions from the Extensions view and open the folder with File \u0026gt; Open Folder. Otherwise:\ncd ~/dev/hello-vcpkg code . Create .vscode/settings.json:\n{ \u0026#34;cmake.useCMakePresets\u0026#34;: \u0026#34;always\u0026#34;, \u0026#34;cmake.configureOnOpen\u0026#34;: true, \u0026#34;cmake.buildBeforeRun\u0026#34;: true, \u0026#34;C_Cpp.default.configurationProvider\u0026#34;: \u0026#34;ms-vscode.cmake-tools\u0026#34;, \u0026#34;files.associations\u0026#34;: { \u0026#34;CMakeLists.txt\u0026#34;: \u0026#34;cmake\u0026#34; } } What these do:\ncmake.useCMakePresets tells CMake Tools to use CMakePresets.json instead of asking you to pick a kit. cmake.configureOnOpen configures the project when the folder opens, so IntelliSense has real compile flags quickly. cmake.buildBeforeRun rebuilds the launch target before starting the debugger. This replaces a preLaunchTask in launch.json. C_Cpp.default.configurationProvider makes the C/C++ extension ask CMake Tools for include paths and definitions. This is why you do not need a hand-written c_cpp_properties.json. If you followed the single-file VS Code tutorial and already have a .vscode/c_cpp_properties.json, delete it or set its configurationProvider to ms-vscode.cmake-tools as well. A configuration file in the workspace takes precedence over the default setting, and a stale one will keep showing the old include paths.\nOptionally, add .vscode/extensions.json so anyone opening the repository is prompted to install the same two extensions:\n{ \u0026#34;recommendations\u0026#34;: [ \u0026#34;ms-vscode.cpptools\u0026#34;, \u0026#34;ms-vscode.cmake-tools\u0026#34; ] } Open the project root in VS Code, not the build directory. Then run these commands from the Command Palette:\nCMake: Select Configure Preset → debug. CMake: Configure. CMake: Build. CMake: Set Launch/Debug Target → hello. The CMake Tools status bar shows the active preset and build target. If it still asks you to select a kit, cmake.useCMakePresets is not set to \u0026quot;always\u0026quot; or the folder was opened above the project root.\nDebug configuration #Create .vscode/launch.json:\n{ \u0026#34;version\u0026#34;: \u0026#34;0.2.0\u0026#34;, \u0026#34;configurations\u0026#34;: [ { \u0026#34;name\u0026#34;: \u0026#34;Debug hello\u0026#34;, \u0026#34;type\u0026#34;: \u0026#34;cppdbg\u0026#34;, \u0026#34;request\u0026#34;: \u0026#34;launch\u0026#34;, \u0026#34;program\u0026#34;: \u0026#34;${command:cmake.launchTargetPath}\u0026#34;, \u0026#34;cwd\u0026#34;: \u0026#34;${command:cmake.getLaunchTargetDirectory}\u0026#34;, \u0026#34;args\u0026#34;: [], \u0026#34;stopAtEntry\u0026#34;: false, \u0026#34;environment\u0026#34;: [], \u0026#34;externalConsole\u0026#34;: false, \u0026#34;MIMode\u0026#34;: \u0026#34;gdb\u0026#34;, \u0026#34;miDebuggerPath\u0026#34;: \u0026#34;/usr/bin/gdb\u0026#34;, \u0026#34;setupCommands\u0026#34;: [ { \u0026#34;description\u0026#34;: \u0026#34;Enable GDB pretty printing\u0026#34;, \u0026#34;text\u0026#34;: \u0026#34;-enable-pretty-printing\u0026#34;, \u0026#34;ignoreFailures\u0026#34;: true } ] } ] } ${command:cmake.launchTargetPath} is resolved by CMake Tools to the binary for the selected launch target, so there is no hard-coded output path. ${command:cmake.getLaunchTargetDirectory} sets the working directory to the binary\u0026rsquo;s directory. If your program loads assets relative to the repository root, change cwd to ${workspaceFolder}.\nThere is deliberately no tasks.json. CMake Tools owns configuring and building; duplicating that in a task is how the two get out of sync. Use tasks.json only for jobs CMake does not know about, such as running a code generator.\n7. Debug it #Open main.cpp, click the gutter next to the fmt::print line to set a breakpoint, and press F5. The debugger stops before the print, the Variables pane shows name, and the Watch pane can evaluate expressions. Step over the call with F10, or step into a function with F11 when debug information is available.\nSet \u0026quot;stopAtEntry\u0026quot;: true in launch.json if you want the debugger to stop in main before anything runs. Add runtime arguments to the \u0026quot;args\u0026quot; array, for example [\u0026quot;--verbose\u0026quot;], and they will be passed to the program.\nIf breakpoints show as hollow circles, the binary was built without debug information. Check that the debug preset is selected and that CMAKE_BUILD_TYPE is Debug in build/debug/CMakeCache.txt.\n8. Add and remove dependencies #Adding a library is a three-step loop. For example, for JSON support:\nvcpkg add port nlohmann-json Then in CMakeLists.txt:\nfind_package(nlohmann_json CONFIG REQUIRED) target_link_libraries(hello PRIVATE nlohmann_json::nlohmann_json) Finally, reconfigure so CMake picks up the new package and IntelliSense sees the headers:\nCommand Palette → CMake: Configure, or cmake --preset debug from a terminal. To remove a dependency, edit vcpkg.json to delete it and remove the find_package/target_link_libraries lines from CMakeLists.txt, then reconfigure. vcpkg remove is for classic mode; in manifest mode the manifest is the source of truth.\nThe next configure installs the new dependency — from vcpkg\u0026rsquo;s binary cache if it has been built before — and CMake regenerates the build files. This is normal; subsequent builds are incremental.\n9. What to commit #Commit the files that describe the environment:\n.gitignore CMakeLists.txt CMakePresets.json vcpkg.json vcpkg-configuration.json main.cpp .vscode/settings.json .vscode/launch.json .vscode/extensions.json Ignore the generated directories:\nbuild/ vcpkg_installed/ .vscode/ipch/ build/ contains the CMake cache, the binaries, and the vcpkg-installed packages. Anything in it is reproducible from the files above.\nTroubleshooting # Symptom Fix vcpkg: command not found The shell has not reloaded, or PATH does not include $VCPKG_ROOT. Run source ~/.bashrc, then echo \u0026quot;$VCPKG_ROOT\u0026quot; and vcpkg version. Could not find a package configuration file provided by \u0026quot;fmt\u0026quot; The toolchain file was not applied, or the manifest is out of date. Check that CMAKE_TOOLCHAIN_FILE appears in build/debug/CMakeCache.txt, run vcpkg add port fmt, and reconfigure. If you changed the toolchain after configuring, delete build/ (or run CMake: Delete Cache and Reconfigure) and configure again. IntelliSense cannot find fmt/core.h but the build works C_Cpp.default.configurationProvider is missing or pointed at the wrong extension. Set it to ms-vscode.cmake-tools, run CMake: Configure, then C/C++: Reset IntelliSense Database. CMake Tools keeps asking for a kit Set cmake.useCMakePresets to \u0026quot;always\u0026quot; and select the debug preset. VS Code cannot see VCPKG_ROOT The editor was launched from the desktop and did not inherit your shell. Start it with code . from a configured terminal, or move the exports to ~/.profile. The debugger will not start Select a launch target first (CMake: Set Launch/Debug Target), make sure program resolves to an existing binary, and check that /usr/bin/gdb exists. vcpkg bootstrap fails or files are not writable Missing curl, zip, or tar; or the checkout was bootstrapped with sudo. Install the tools and sudo chown -R \u0026quot;$USER\u0026quot;:\u0026quot;$USER\u0026quot; /opt/vcpkg. The first configure takes minutes vcpkg is building dependencies from source. Later builds use its binary cache. Wrapping up #The final loop is short: declare a dependency in vcpkg.json, add a find_package and a target_link_libraries line, reconfigure, and keep coding. CMake handles the build graph; CMake Tools exposes it to VS Code; the C/C++ extension supplies IntelliSense and GDB from the same information.\nThat is a lot more setup than the single-file g++ task in the VS Code tutorial, but it is setup you do once per project. After that, adding a library is a manifest edit instead of a hunt through compiler flags, and a new machine needs the toolchain plus a configure to reproduce the build.\nThe VS Code C++ on Linux tutorial is still worth reading for the editor basics, and the vcpkg CMake tutorial covers the same manifest workflow from Microsoft\u0026rsquo;s side.\n","date":"20 November 2026","permalink":"https://blog.xyzzy.run/posts/c++-linux-vscode/","section":"Blog","summary":"Set up a modern C++ workflow on Linux with VS Code, CMake, Ninja, and vcpkg: IntelliSense, builds, and GDB debugging from one workspace.","title":"A C++ Dev Environment on Linux with VS Code, CMake, and vcpkg"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/c++/","section":"Tags","summary":"","title":"C++"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/cmake/","section":"Tags","summary":"","title":"CMake"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/categories/development/","section":"Categories","summary":"","title":"Development"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/vcpkg/","section":"Tags","summary":"","title":"Vcpkg"},{"content":"","date":null,"permalink":"https://blog.xyzzy.run/tags/vs-code/","section":"Tags","summary":"","title":"VS Code"}]