Trying to play with postgres and docker:
docker run --name pg -v /Users/xxx/docker/data:/var/lib/postgresql/data -d postgres
stops immediately. Run the image without -v the container keeps running on. If I login via /bin/sh I can see the mountpoint with the postgres default databases:
root@f9e0e92dae26:/# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
none 19049892 737424 17321744 5% /
tmpfs 1025332 0 1025332 0% /dev
shm 65536 8 65528 1% /dev/shm
none 116884912 52807056 64077856 46% /var/lib/postgres/data
/dev/sda1 19049892 737424 17321744 5% /var/lib/postgresql/data
But I cannot share them with the host in the manner of -v option says. What's wrong here?
The log says:
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
initdb: could not create directory "/var/lib/postgresql/data/pg_wal/archive_status": Permission denied
initdb: removing contents of data directory "/var/lib/postgresql/data"
I've tried to pass an additional shared directory to the VM, beside /Users and /, in my case /Users/xxx/docker/data, restarting the VM but that seems not to work. Within the VM (docker-machine ssh) I can see now /data mounted. Docker machine seems to mount the last part of the full path. Any explanation? So with that maybe the offical postgres images could be changed (in the dockerfile?) to change the base path, examples appreciated.
After getting the exact same error, what worked for me was pruning the volumes. I never could figure out why there wasn't enough space in the first place.
Before you run the command below for any pruning, be sure to read the details here: https://docs.docker.com/config/pruning/#prune-everything
If you can bear to prune the volumes, this should do the trick to eliminate the OP's error:
docker volume prune
Edit:
It appears some need to prune more than the volumes. An earlier version of this of this answer accounted for that, so I'm now including it again.
To do a system prune, run:
docker system prune --volumes
Or if you really want to get rid of everything, run:
docker system prune --volumes --all
Following up on Nicolas's answer,
In my case, just pruning volumes wasn't sufficient, I pruned everything (images, containers, volumes, and networks) and then it started working. Command: docker system prune --volumes
Note Make sure the deletion doesn't affect any of the other setup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With