# Postgres refuses to launch, directory is empty

**URL:** <https://forums.docker.com/t/postgres-refuses-to-launch-directory-is-empty/46234>\
**Category:** General\
**Tags:** docker\
**Created:** [February 12, 2018, 8:21pm UTC](https://forums.docker.com/t/postgres-refuses-to-launch-directory-is-empty/46234 "2018-02-12T20:21:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterbocan](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@peterbocan](https://forums.docker.com/u/peterbocan)\
**Post date:** [February 12, 2018, 8:21pm UTC](https://forums.docker.com/t/postgres-refuses-to-launch-directory-is-empty/46234/1 "2018-02-12T20:21:58Z")

</div>

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

```auto
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.

```auto
version: '3'
services:
  postgres:
    image: postgres:10.1-alpine
    ports:
      - "5432:5432"
    networks:
      - db
    environment:
      POSTGRES_USER: x
      POSTGRES_PASSWORD: y
    volumes:
      - pgdata:/var/lib/postgresql/data
networks:
  proxy:
    driver: bridge
  db:
    driver: bridge
volumes:
  pgdata:

```

---

<div class="post-metadata">

**Author:** ![sdetweil](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sdetweil](https://forums.docker.com/u/sdetweil)\
**Post date:** [February 12, 2018, 9:27pm UTC](https://forums.docker.com/t/postgres-refuses-to-launch-directory-is-empty/46234/2 "2018-02-12T21:27:57Z")

</div>

> [@peterbocan](#):
>
> volumes:  
> - pgdata:/var/lib/postgresql/data

the pgdata folder is not empty…

---

<div class="post-metadata">

**Author:** ![peterbocan](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@peterbocan](https://forums.docker.com/u/peterbocan)\
**Post date:** [February 12, 2018, 10:31pm UTC](https://forums.docker.com/t/postgres-refuses-to-launch-directory-is-empty/46234/3 "2018-02-12T22:31:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sdetweil](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sdetweil](https://forums.docker.com/u/sdetweil)\
**Post date:** [February 12, 2018, 11:00pm UTC](https://forums.docker.com/t/postgres-refuses-to-launch-directory-is-empty/46234/4 "2018-02-12T23:00:00Z")

</div>

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’…

---

<div class="post-metadata">

**Author:** ![dmaze](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@dmaze](https://forums.docker.com/u/dmaze)\
**Post date:** [February 13, 2018, 1:30am UTC](https://forums.docker.com/t/postgres-refuses-to-launch-directory-is-empty/46234/5 "2018-02-13T01:30:06Z")

</div>

> [@sdetweil](#):
>
> the ‘volume’ is a docker term for the connectivity to a host folder… doesn’t have any concept of data in the folder.

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.

---

<div class="post-metadata">

**Author:** ![sdetweil](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sdetweil](https://forums.docker.com/u/sdetweil)\
**Post date:** [February 13, 2018, 4:20am UTC](https://forums.docker.com/t/postgres-refuses-to-launch-directory-is-empty/46234/6 "2018-02-13T04:20:46Z")

</div>

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

the reuse is the key behavior difference

---

<div class="post-metadata">

**Author:** ![peterbocan](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@peterbocan](https://forums.docker.com/u/peterbocan)\
**Post date:** [February 15, 2018, 3:49pm UTC](https://forums.docker.com/t/postgres-refuses-to-launch-directory-is-empty/46234/7 "2018-02-15T15:49:12Z")

</div>

I have nuked every volume, it got stuck somehow. 😕

---

<div class="post-metadata">

**Author:** ![sdetweil](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sdetweil](https://forums.docker.com/u/sdetweil)\
**Post date:** [February 15, 2018, 5:15pm UTC](https://forums.docker.com/t/postgres-refuses-to-launch-directory-is-empty/46234/8 "2018-02-15T17:15:55Z")

</div>

and its ok now?  
need 2o chars

---

<div class="post-metadata">

**Author:** ![peterbocan](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@peterbocan](https://forums.docker.com/u/peterbocan)\
**Post date:** [February 15, 2018, 5:18pm UTC](https://forums.docker.com/t/postgres-refuses-to-launch-directory-is-empty/46234/9 "2018-02-15T17:18:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![banan314](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/banan314/32/46880_2.png) [@banan314](https://forums.docker.com/u/banan314)\
**Post date:** [April 10, 2024, 4:01am UTC](https://forums.docker.com/t/postgres-refuses-to-launch-directory-is-empty/46234/10 "2024-04-10T04:01:53Z")

</div>

I followed this answer and it worked [Docker-Compose postgres upgrade initdb: error: directory "/var/lib/postgresql/data" exists but is not empty - Stack Overflow](https://stackoverflow.com/a/63824663/7769052)
