<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Overnight.Host</title>
    <description>The latest articles on DEV Community by Overnight.Host (@overnight_host).</description>
    <link>https://dev.to/overnight_host</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4254596%2Fd7b1e660-71d7-4b7b-81f8-8b979fa35a03.png</url>
      <title>DEV Community: Overnight.Host</title>
      <link>https://dev.to/overnight_host</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/overnight_host"/>
    <language>en</language>
    <item>
      <title>Docker Compose on a 1 GiB VPS: memory limits, swap and log rotation that keep it up</title>
      <dc:creator>Overnight.Host</dc:creator>
      <pubDate>Fri, 20 Nov 2026 07:05:28 +0000</pubDate>
      <link>https://dev.to/overnight_host/docker-compose-on-a-1-gib-vps-memory-limits-swap-and-log-rotation-that-keep-it-up-4n9m</link>
      <guid>https://dev.to/overnight_host/docker-compose-on-a-1-gib-vps-memory-limits-swap-and-log-rotation-that-keep-it-up-4n9m</guid>
      <description>&lt;p&gt;Docker is not the problem on a 1 GiB server. The daemon idles under 50 MB. The real problem is that Compose will happily start five containers with no memory limits at all, and when memory runs out the kernel's OOM killer does not ask which one you meant to keep. Sometimes it picks sshd.&lt;/p&gt;

&lt;p&gt;Here are six things to set up on a small box before you add a single container.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Install Docker Engine from Docker's repo, not docker.io
&lt;/h2&gt;

&lt;p&gt;Ubuntu's own repository ships an old, renamed build called &lt;code&gt;docker.io&lt;/code&gt;. Add Docker's official apt repository instead (the steps are in Docker's Ubuntu install guide), then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker &lt;span class="s2"&gt;"$USER"&lt;/span&gt;
newgrp docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From here on it is &lt;code&gt;docker compose&lt;/code&gt;, a subcommand of the docker CLI with no hyphen, not the old standalone &lt;code&gt;docker-compose&lt;/code&gt; binary. The compose file syntax is the same either way.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Add swap before you add containers
&lt;/h2&gt;

&lt;p&gt;A 1 GiB plan has exactly 1 GiB of RAM and nothing behind it. Swap does not make anything faster. It turns a hard crash into a slow one you can see coming with &lt;code&gt;free -h&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'/swapfile none swap sw 0 0'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sudo tee -a /etc/fstab

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'vm.swappiness=10'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sudo tee /etc/sysctl.d/99-swappiness.conf
sudo sysctl --system
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two gigabytes is a reasonable default on a 25 GB disk. The low swappiness keeps swap as an emergency buffer rather than an active memory tier.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Give every service a memory limit (and know which syntax works)
&lt;/h2&gt;

&lt;p&gt;This one catches a lot of people. Many compose files use a &lt;code&gt;deploy.resources.limits.memory&lt;/code&gt; block. On a plain &lt;code&gt;docker compose up&lt;/code&gt;, that block is parsed and silently ignored. &lt;code&gt;deploy&lt;/code&gt; is written for Swarm, and outside Swarm mode Compose only honours it when you run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker compose --compatibility up -d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you would rather not remember a flag on every run, use &lt;code&gt;mem_limit&lt;/code&gt; directly. It is a legacy property that the compose plugin still fully supports, and it applies with a plain &lt;code&gt;up&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;uptime-kuma&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;louislam/uptime-kuma:1.23.16&lt;/span&gt;   &lt;span class="c1"&gt;# example tag only, check the current release
&lt;/span&gt;    &lt;span class="na"&gt;restart&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;unless-stopped&lt;/span&gt;
    &lt;span class="na"&gt;mem_limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;200m&lt;/span&gt;
    &lt;span class="na"&gt;memswap_limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;400m&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;kuma_data:/app/data&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"127.0.0.1:3001:3001"&lt;/span&gt;

&lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;kuma_data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;mem_limit&lt;/code&gt; caps physical memory. &lt;code&gt;memswap_limit&lt;/code&gt; caps memory plus swap, so setting it to double lets the container spill a little into swap instead of being killed the moment it touches the ceiling. Set both on every service before you decide the box "isn't big enough". Four unbounded containers fighting each other is a resource allocation problem, not a RAM problem.&lt;/p&gt;

&lt;p&gt;To check what is really using memory, &lt;code&gt;docker stats&lt;/code&gt; shows live per-container cgroup usage, which is what your limits are measured against. Cross-check with &lt;code&gt;free -h&lt;/code&gt;: if the containers look fine but swap is busy, something outside Docker, or a container without a limit, is the culprit.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Rotate logs, or the disk fills quietly
&lt;/h2&gt;

&lt;p&gt;The default &lt;code&gt;json-file&lt;/code&gt; logging driver keeps every line a container has ever printed, with no size cap. A chatty service can grow its log into gigabytes over a few months, and you only notice when the disk is full. Set a daemon-wide default in &lt;code&gt;/etc/docker/daemon.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"log-driver"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"json-file"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"log-opts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"max-size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"10m"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"max-file"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"3"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then &lt;code&gt;sudo systemctl restart docker&lt;/code&gt;. It only applies to containers created after the restart, so run &lt;code&gt;docker compose up -d --force-recreate&lt;/code&gt; for anything already running. Three files of 10 MB caps each service at 30 MB of logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Pin image tags and prune safely
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;latest&lt;/code&gt; is not a version. Pin an explicit tag (or a digest, &lt;code&gt;image: name@sha256:...&lt;/code&gt;, for anything holding data you care about) and upgrade on purpose with &lt;code&gt;docker compose pull &amp;amp;&amp;amp; docker compose up -d&lt;/code&gt; after reading the changelog.&lt;/p&gt;

&lt;p&gt;Every pull leaves old layers behind. The safe routine cleanup is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker image prune -f
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It removes only dangling images and never touches anything a running or stopped container still references. &lt;code&gt;docker system prune -af --volumes&lt;/code&gt; is the aggressive version, and &lt;code&gt;--volumes&lt;/code&gt; deletes every volume not attached to a container, including the data of a service you stopped but never removed. Run it by hand, read the list, and never put it in an unattended cron job.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. HTTPS with one Caddy, and a note on NAT IPv4
&lt;/h2&gt;

&lt;p&gt;For anything you open in a browser, Caddy requests and renews the certificate on its own:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;reverse_proxy&lt;/span&gt; &lt;span class="mf"&gt;127.0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3001&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bind container ports to &lt;code&gt;127.0.0.1&lt;/code&gt; (as above) so Caddy is the only thing reachable from the internet, and run one Caddy for everything. It idles comfortably under 50 MB.&lt;/p&gt;

&lt;p&gt;One catch before you buy: cheap VPS plans often give you NAT IPv4, a shared address with a few forwarded ports. Caddy needs to own ports 80 and 443 on a public address to serve plain HTTPS. With NAT, either get a dedicated IPv4 or skip the reverse proxy for services that only make outbound calls, like a backup job, a sync agent or an outbound automation workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually fits in 1 GiB
&lt;/h2&gt;

&lt;p&gt;With limits in place, these fit comfortably: Uptime Kuma watching a few dozen endpoints (under 100 MB idle), Vaultwarden (under 50 MB idle), and a small n8n with a handful of workflows. One or two of them together still leaves headroom.&lt;/p&gt;

&lt;p&gt;These realistically do not fit: Nextcloud with preview generation, Gitea plus CI runners, and anything built on Elasticsearch. The pattern is the same each time. The base app is fine, but one feature (thumbnails, CI jobs, a search index) spikes far above idle. Read the feature list with that in mind, not just the "runs on a Raspberry Pi" line.&lt;/p&gt;

&lt;p&gt;That is the whole setup. If you want the longer version with the full apt repository steps and an FAQ, we keep it in our guides, written for our KVM VPS plans that run on single-tenant bare metal in Dallas, TX and Charlotte, NC: &lt;a href="https://overnight.host/guides/docker-compose-on-a-1gib-vps/" rel="noopener noreferrer"&gt;Docker Compose on a 1 GiB VPS&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://overnight.host/guides/docker-compose-on-a-1gib-vps/" rel="noopener noreferrer"&gt;overnight.host&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
      <category>linux</category>
      <category>selfhosted</category>
    </item>
  </channel>
</rss>
