The Postgres container cannot write postmaster.pid because Docker is out of disk
FATAL: could not write lock file "postmaster.pid": No space left on deviceShort answer
The error means the filesystem Docker stores the container on is full, not necessarily your whole disk. Run docker system df to see what takes the space, remove unused images, containers and build cache, and on Docker Desktop raise the disk usage limit if it is reached.
Fix it fast
1Find out which cause you have
Measure Docker's own usage and the host disk. The reclaimable column shows what can be removed safely.
docker system df df -h2Match what you see, then jump to its fix
- 1
docker system df shows a large RECLAIMABLE number.Unused images, containers and build cache fill Docker's storageFix - 2
The host disk has free space, but Docker's own storage is at its maximum.Docker Desktop's disk usage limit is reachedFix - 3
docker system df -v lists the Postgres volume as the biggest item.The database itself has grown to fill its volumeFix
- 1
What does the error look like?
FATAL: could not write lock file "postmaster.pid": No space left on devicecould not write to file ... No space left on device
Cause 1 of 3
Unused images, containers and build cache fill Docker's storage
1Check
Old images, stopped containers and build cache pile up. Volumes are listed separately.
docker system df -v2Fix
Prune what is unused. This does not touch volumes unless you add --volumes, so do not add it for a database host.
docker system prune3Verify
Free space grows, and the container starts.
docker system df
docker compose up -d dbConfirmed by docs.docker.com
Cause 2 of 3
Docker Desktop's disk usage limit is reached
1Check
Docker Desktop on Mac, Windows (Hyper-V) and Linux lets the engine use only a set amount of disk.
docker system df2Fix
Open Settings, then Resources, then Advanced, and raise the Disk usage limit after cleaning.
# Docker Desktop > Settings > Resources > Advanced > Disk usage limit3Verify
Restart Docker Desktop and start the database container.
docker compose up -d db && docker compose logs db | tail -n 5Confirmed by docs.docker.com
Cause 3 of 3
The database itself has grown to fill its volume
1Check
Look at the volume size, then at which tables are large.
docker system df -v
docker compose exec db psql -U postgres -c "select pg_size_pretty(pg_database_size(current_database()))"2Fix
Delete data you no longer need, then give the volume more room (a bigger disk limit or host disk). Never delete files inside the data directory by hand.
docker compose exec db psql -U postgres -c 'VACUUM'3Verify
Database size and free space look healthy.
docker system dfConfirmed by docs.docker.com
How do I stop it coming back?
- Prune unused images and build cache on a schedule on build machines.
- Alert on disk usage before it reaches 90 percent.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Databases
Django cannot connect to PostgreSQL: connection refused on port 5432, locally or in Docker
Is the server running on that host and accepting TCP/IP connections?
Connection refused means nothing accepted the connection at the host and port Django used.
4 causes, each with a fixDatabases
Node.js in Docker Compose cannot find mysql2/promise
The app works on the host but fails after docker compose up
mysql2/promise is a path inside the mysql2 package.
2 causes, each with a fixDatabases
A container cannot resolve the name of its database container
php_network_getaddresses: getaddrinfo failed
127.0.0.11 is Docker's own DNS server for custom networks.
3 causes, each with a fixDatabases
EF Core says 'transient failure' when it cannot reach PostgreSQL in Docker
The query fails only after a delay, because the connection is retried several times
The transient failure message comes from EF Core's retry layer, which hides the underlying connection error.
3 causes, each with a fixDatabases
Keycloak in a container will not let you create the first admin user
You need local access to create the initial admin user.
Keycloak only lets you create the first admin from a local network connection, and a container does not count.
2 causes, each with a fixDatabases
The MariaDB or MySQL container ignores the root password you set
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
The official MariaDB and MySQL images apply their password variables only while initialising an empty data directory.
3 causes, each with a fix