---
title: "Docker security checklist for an internet-facing server · CloudSat"
description: "Docker security checklist for internet-facing servers: guard the socket, stop ports slipping past the firewall, drop privileges, pin images, keep secrets out."
url: https://cloudsat.io/learn/docker-security-checklist-for-servers
updated: 2026-11-18T12:00:00Z
source: CloudSat (https://cloudsat.io/). Prices in USD.
---

[DevOps](https://cloudsat.io/learn/topic/devops-and-automation)

# Docker security checklist for an internet-facing server

Docker security checklist for internet-facing servers: guard the socket, stop ports slipping past the firewall, drop privileges, pin images, keep secrets out.

CloudSat team November 18, 2026 7 min read

Docker's defaults are tuned for a developer laptop behind a home router: everything is reachable, everything runs as root, and nothing gets in your way. On a server with a public IP address, a few of those defaults turn small mistakes into incidents. This checklist goes layer by layer, from the daemon to the images, with a command to verify each point on a running host.

## The daemon and who can talk to it

The Docker API can start a container that mounts the host's root file system, so anything that reaches the API controls the machine. Three paths lead there.

**The `docker` group.** Its members talk to the daemon without `sudo`, which makes membership equivalent to root. Keep the group to administrators who already have root, and list it now and then:

```bash
getent group docker
```

**A TCP socket.** Never start the daemon with `-H tcp://0.0.0.0:2375`. That port has no authentication, and scanners look for it constantly. For remote administration, use the CLI over SSH, which needs no open daemon port at all; [remote Docker over SSH](https://cloudsat.io/learn/remote-docker-builds-over-ssh) shows the setup.

**Socket mounts.** A container started with `-v /var/run/docker.sock:/var/run/docker.sock` holds the same power as the `docker` group. Dashboards, updaters and reverse proxies often ask for it. Give them a socket proxy instead: a small container that forwards only the API calls you allow (read-only container listings, for example) and refuses the rest. Find existing socket mounts with:

```bash
docker ps -q | xargs -r docker inspect --format '{{.Name}}{{range .Mounts}} {{.Source}}{{end}}' | grep docker.sock
```

### Rootless mode and user namespaces

Rootless mode runs the daemon and its containers inside a user namespace as an ordinary user, so an escape from a container lands in an unprivileged account. Install `uidmap`, make sure the user has subordinate ID ranges in `/etc/subuid` and `/etc/subgid`, then run `dockerd-rootless-setuptool.sh install` as that user. The main trade-offs: ports below 1024 need a sysctl (`net.ipv4.ip_unprivileged_port_start`), and the socket moves to `/run/user/<uid>/docker.sock`.

`userns-remap` is the middle ground. The daemon still runs as root, but root inside a container maps to an unprivileged range on the host. Either option is stronger than the default. Pick one when you build a new server rather than retrofitting it into a busy host, because switching means pulling images again and fixing the ownership of existing volumes.

## Network exposure

This is the mistake that bites most often. When you publish a port with `-p 8080:80`, Docker writes its own packet filtering rules, and Docker's documentation states plainly that with UFW, packets are routed before the firewall rules can be applied. A database published "just for a minute" is reachable from the internet even though `ufw status` says otherwise.

Fix it at the source. Publish admin panels and databases on the loopback interface only, and let a reverse proxy on the host terminate HTTPS:

```yaml
services:
  app:
    image: ghcr.io/example/app:2.3.1
    ports:

      - "127.0.0.1:8080:8080"   # reachable from the host only

  db:
    image: postgres:16
    # no ports: other services reach it as db:5432 on the Compose network
```

When a port must stay public but limited to known addresses, put the rule in the `DOCKER-USER` chain, which Docker evaluates before its own rules:

```bash
# allow port 8443 only from one office address (ext_if = your public interface, e.g. eth0)
sudo iptables -I DOCKER-USER -i eth0 -p tcp -m conntrack --ctorigdstport 8443 ! -s 198.51.100.24 -j DROP
```

The `conntrack` match is needed because Docker rewrites destination addresses before the packet reaches this chain. Rules added by hand do not survive a reboot unless you persist them, which is one more reason to prefer loopback binding.

A firewall outside the server is the second layer. On CloudSat, a [cloud firewall](https://cloudsat.io/docs/cloud-firewalls) drops inbound traffic before it reaches the server, so no rule Docker writes inside the machine can reopen a port the cloud firewall closes. Audit what is exposed right now:

```bash
docker ps --format '{{.Names}}\t{{.Ports}}' | grep -E '0\.0\.0\.0|\[::\]'
```

## Limits for each container

A container should get the least it needs to run. In Compose, the hardening fits in a few lines per service:

```yaml
services:
  api:
    image: registry.example.com/shop/api:1.8.0
    user: "10001:10001"
    read_only: true
    tmpfs:

      - /tmp

    cap_drop: [ALL]
    security_opt:

      - no-new-privileges:true

    pids_limit: 200
    mem_limit: 512m
    cpus: 1.0
```

| Setting | What it prevents |
| --- | --- |
| `user` | Running as root inside the container, which matters on the day of a container escape |
| `read_only` plus `tmpfs` | Attackers or bugs writing tools and scripts into the image's file system |
| `cap_drop: [ALL]` | Kernel capabilities such as raw sockets or changing file ownership |
| `no-new-privileges` | Gaining privileges through setuid binaries inside the container |
| `pids_limit`, `mem_limit`, `cpus` | A fork bomb or memory leak taking the whole host down |

Start from `cap_drop: [ALL]` and add back only what a container proves it needs. Images whose entrypoint switches users, such as many official database images, typically need `CHOWN`, `SETUID` and `SETGID` back.

Some flags undo all of this at once. `--privileged`, `network_mode: host`, `pid: host` and bind mounts of `/`, `/etc` or `/var/run` should each have a written reason. Find privileged containers with:

```bash
docker ps -q | xargs -r docker inspect --format '{{.Name}} privileged={{.HostConfig.Privileged}} user={{.Config.User}}'
```

An empty `user=` value means the container runs as root.

## Images: know what you run

- **Pick sources deliberately.** Official images, verified publishers, or images you build yourself from a Dockerfile you have read.
- **Pin versions.** `postgres:16.4` instead of `postgres:latest`, and a digest (`@sha256:...`) where you need byte-for-byte repeatability. Updates then happen when you choose, not on the next pull.
- **Prefer small bases.** Slim, Alpine or distroless images carry fewer packages, so fewer vulnerabilities to triage.
- **Scan in CI.** Open-source scanners such as Trivy and Grype, or Docker Scout, report known CVEs in each layer. Fail the build on critical findings that have a fix, and pin the scanner's own version too.
- **Rebuild on a schedule.** A pinned image never receives base-layer fixes by itself. A weekly rebuild and redeploy keeps pins and patches together.

## Secrets stay out of images

Docker's documentation warns that build arguments and environment variables persist in the final image, and `docker history --no-trunc` shows them to anyone who pulls it. Use a BuildKit secret mount during builds:

```dockerfile
# syntax=docker/dockerfile:1
RUN --mount=type=secret,id=npm_token \
    NPM_TOKEN="$(cat /run/secrets/npm_token)" npm ci
```

```bash
docker build --secret id=npm_token,src=$HOME/.npm_token -t shop/web .
```

At runtime, Compose secrets mount a file at `/run/secrets/<name>`, instead of an environment variable that shows up in `docker inspect` and is inherited by every child process:

```yaml
services:
  api:
    secrets: [db_password]
secrets:
  db_password:
    file: ./secrets/db_password.txt
```

Keep `.env` files and the `secrets/` folder out of Git and out of the build context with `.gitignore` and `.dockerignore`, and give them mode `600` on the server.

## Updates and visibility

- Update Docker Engine from Docker's own repository with the rest of the system, and read the release notes for security fixes.
- Recreate containers after pulling new images: `docker compose pull && docker compose up -d`. A pulled image changes nothing until the container is recreated.
- Ship container logs somewhere that outlives the container, and alert on restart loops.
- For a full audit, the CIS Docker Benchmark is the long-form version of this list.

## FAQ

### Are containers a security boundary?

A limited one. Containers share the host kernel, so a kernel bug can cross them. For code you do not trust, such as customer workloads or CI jobs from public pull requests, use separate virtual machines, or a sandboxed runtime such as gVisor or Kata Containers.

### Is rootless Docker worth the trouble?

On a new server that runs your own services, usually yes: it removes the worst outcome of a container escape. On hosts that need privileged containers, host networking or certain storage drivers, the limitations add friction, and `userns-remap` or a separate VM per workload may fit better.

### Does Podman avoid these problems?

Podman runs rootless when an ordinary user starts it and has no central daemon, which shrinks the socket problem. Image hygiene, secrets and published ports still need the same care.

### How do I know if a published port is reachable from outside?

Test from another machine, never from the server itself: `nc -vz 203.0.113.10 5432`. A connection from outside means the port is exposed, whatever the host firewall reports.

**Run it on CloudSat.** Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. [See plans](https://cloudsat.io/plans) or [deploy a server](https://dash.cloudsat.io/console/deploy).

## Keep reading

[All guides in DevOps](https://cloudsat.io/learn/topic/devops-and-automation)

- [List Docker containers with docker ps: filters and formats](https://cloudsat.io/learn/docker-ps-list-filter-and-format-containers): DevOps List Docker containers with docker ps: filters and formats 8 min read
- [Remote Docker builds over SSH: use a VPS as your engine](https://cloudsat.io/learn/remote-docker-builds-over-ssh): DevOps Remote Docker builds over SSH: use a VPS as your engine 7 min read
- [Docker web UIs compared: Portainer, Dockge, Komodo and more](https://cloudsat.io/learn/docker-web-ui-compared): DevOps Docker web UIs compared: Portainer, Dockge, Komodo and more 7 min read
- [Install Docker Engine on Ubuntu or Debian, the official way](https://cloudsat.io/learn/install-docker-engine-on-ubuntu-and-debian): DevOps Install Docker Engine on Ubuntu or Debian, the official way 7 min read
