Docker Community Forums

Share and learn in the Docker community.

Postgres refuses to launch, directory is empty


(Peterbocan) #1

Hello guys I have tried to mount the persistent volume to the PostgreSQL, but Postgres just screws me over saying

postgres_1       | initdb: directory "/var/lib/postgresql/data" exists but is not empty
postgres_1       | If you want to create a new database system, either remove or empty
postgres_1       | the directory "/var/lib/postgresql/data" or run initdb
postgres_1       | with an argument other than "/var/lib/postgresql/data".

and I can not get my head around why? Here is my docker-compose.yml. I am running on MacOS High Sierra (APFS), Docker CE.

version: '3'
    image: postgres:10.1-alpine
      - "5432:5432"
      - db
      - pgdata:/var/lib/postgresql/data
    driver: bridge
    driver: bridge

(Sam) #2

the pgdata folder is not empty…

(Peterbocan) #3

even if the volume is new? Or how should I create empty volume?

(Sam) #4

the ‘volume’ is a docker term for the connectivity to a host folder… doesn’t have any concept of data in the folder.
THAT is an application (postgres) thing

the directory pgdata should have NO files in you are creating a NEW database…

if you are REUSING an existing database then there can be files present (but then you would not say ‘create database’…

(David Maze) #5

In the docker-compose.yml the OP quoted, the volume is a Docker-managed volume, not a bind-mounted host directory.

docker volume ls will show the volumes that exist. Since the default assumption is that they hold valuable data like, say, your database, the default tooling is a little hesitant to delete them; and when you restart the container it will pick up the old volume again. docker volume rm will delete an (unused) volume that’s lying around. You need to give an explicit docker-compose down -v option to cause Compose to remove named volumes.

(Sam) #6

its still a bind mounted volume, just using the volume id from docker create volume.

the reuse is the key behavior difference

(Peterbocan) #7

I have nuked every volume, it got stuck somehow. :confused:

(Sam) #8

and its ok now?
need 2o chars

(Peterbocan) #9

Yes, it works! Docker compose still refuses to watch the changes on the drive so I have to manually build the images. But the issue is solved.