11

Since yesterday, I try to launch my docker project on Windows (Bootcamp MacBook Pro), and I have just one issue left : PostgreSQL image.

Error message :

postgres_1         | The files belonging to this database system will be owned by user "postgres".
postgres_1         | This user must also own the server process.
postgres_1         |
postgres_1         | The database cluster will be initialized with locale "en_US.utf8".
postgres_1         | The default database encoding has accordingly been set to "UTF8".
postgres_1         | The default text search configuration will be set to "english".
postgres_1         |
postgres_1         | Data page checksums are disabled.
postgres_1         |
postgres_1         | fixing permissions on existing directory /var/lib/postgresql/data ... ok
postgres_1         | creating subdirectories ... ok
postgres_1         | selecting default max_connections ... 20
postgres_1         | selecting default shared_buffers ... 400kB
postgres_1         | selecting dynamic shared memory implementation ... posix
postgres_1         | creating configuration files ... ok
postgres_1         | 2019-01-22 16:57:37.016 UTC [79] FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
postgres_1         | 2019-01-22 16:57:37.016 UTC [79] HINT:  The server must be started by the user that owns the data directory.
postgres_1         | child process exited with exit code 1
postgres_1         | initdb: removing contents of data directory "/var/lib/postgresql/data"
postgres_1         | running bootstrap script ... kibati-docker_postgres_1 exited with code 1

I've searched everywhere, tried everything, and still have this issue…

What I tried is :

  • Create docker volume with docker volume create --name postgres -d local and use it in my docker-compose.yml

docker-compose.yml

version: '2'

services:
  postgres:
    image: postgres:latest
    ports:
      - "5432:5432"
    volumes:
      - postgres:/var/lib/postgresql/data

  networks:
    internal_ip:
      ipv4_address: 192.168.1.2

  volumes:
    postgres:
      external: true
  • Add volume directly in docker compose

volume sample

volumes:
  postgres:
    driver: local
  • Using relative or absolute Windows paths
  • Declare multiple volumes for differents PostgreSQL folders (conf, data…)

I tried to docker compose down, restart computer, remove images, nothing change, same error.

I already checked Shared Drive box in Docker Settings.

Sources of what I've tried :

https://glennsarti.github.io/blog/puppet-in-docker/

https://forums.docker.com/t/trying-to-get-postgres-to-work-on-persistent-windows-mount-two-issues/12456/5

https://forums.docker.com/t/data-directory-var-lib-postgresql-data-pgdata-has-wrong-ownership/17963/28

https://github.com/docker-library/postgres/issues/435

http://www.lukaszewczak.com/2016/09/run-postgresql-using-docker-with.html

https://gdevops.gitlab.io/tuto_docker/tutoriels/postgresql/postgresql.html

https://devask.cz/questions/48645804/mount-postgres-data-to-windows-host-directory

Is anyone as a working solution ? I will continue to make it work, and update post if I found Something.

Thanks in advance.

2
  • Are you having the same volume issue than in the answer for this question? superuser.com/questions/789754/… > In case of Docker images with volumes when you download the image you need to create a similar volume on your host too, because downloading a docker image doesn t download the docker volume. Commented Jan 29, 2019 at 3:52
  • It's what I've done, creating manually the volume and bind it to postgresql image in docker-compose. And it didn't worked. Commented Jan 29, 2019 at 11:40

2 Answers 2

10

I've finally figured out what went wrong when I tried to use a volume for PostgreSQL data.

I had no idea that we used a docker-compose.override.yml, which declare a volume with a Windows path.

So here is a working solution to have PostgreSQL on Docker for Windows, with persisted data :

version: '2'

services:
  postgres:
    image: postgres:11.5
    ports:
      - 5432:5432
    volumes: 
      - pgdata:/var/lib/postgresql/data
      - pgconf:/etc/postgresql
      - pglog:/var/log/postgresql

volumes:
  pgdata:
    driver: local
  pgconf:
    driver: local
  pglog: 
    driver: local

(no additional command required)

Sign up to request clarification or add additional context in comments.

2 Comments

Interesting, it does work. Could you tell though where the actual files are stored on the windows file explorer?
I tested by starting and restarting the server, and indeed the data is persistent
1

This solution worked for me: Run the command docker volume create --name=pgdata

   version: '2'

services:
  postgres:
    image: postgres:latest
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data

  networks:
    internal_ip:
      ipv4_address: 192.168.1.2

 volumes:
   pgdata:
      external: true

Make sure volumes is at the same indentation level as services

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.