Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows 10 is always FATAL: data directory "/var/lib/postgresql/data" has wrong ownership #435

Closed
ayuthmang opened this issue Apr 23, 2018 · 12 comments
Labels
question Usability question, not directly related to an error with the image

Comments

@ayuthmang
Copy link

ayuthmang commented Apr 23, 2018

On Windows 10 Pro is always failed while docker-compose up, otherwise on mac is work perfectly.

Here are some my docker-compose file:

version: '2'
services:
.
.
.
.
  postgresql:
    image: postgres:93
    container_name: lnpp-postgresql
    restart: always
    environment:
      POSTGRES_PASSWORD: asdf
    volumes:
      - ./postgresql/data:/var/lib/postgresql/data
      - ./postgresql/conf:/etc/postgresql/
    ports:
      - "5432:5432"
    networks:
      lnpp-network:
        ipv4_address: ${lnpp_POSTGRES_IP}

networks:
  lnpp-network:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: ${lnpp_SUBNET}
          gateway: ${lnpp_GATEWAY}

and there are some logs.

lnpp-postgresql | FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT:  The server must be started by the user that owns the data directory.
lnpp-postgresql exited with code 1
lnpp-postgresql | FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT:  The server must be started by the user that owns the data directory.
lnpp-postgresql | FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT:  The server must be started by the user that owns the data directory.
lnpp-postgresql | FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT:  The server must be started by the user that owns the data directory.
lnpp-postgresql exited with code 1
lnpp-postgresql | FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT:  The server must be started by the user that owns the data directory.
lnpp-postgresql | FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT:  The server must be started by the user that owns the data directory.
lnpp-postgresql | FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT:  The server must be started by the user that owns the data directory.
lnpp-postgresql | FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT:  The server must be started by the user that owns the data directory.
lnpp-postgresql | FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT:  The server must be started by the user that owns the data directory.
lnpp-postgresql exited with code 1
@wglambert wglambert added the question Usability question, not directly related to an error with the image label Apr 25, 2018
@maiorano84
Copy link

I have this same issue only on Windows. Everywhere else is fine.

The only way I was able to get around this was through a named volume mount:

postgresql:
  image: postgres:93
  volumes:
  - postgres:/var/lib/postgresql/data
  - ./postgresql/conf:/etc/postgresql/
...
volumes:
  postgres:

@tianon
Copy link
Member

tianon commented May 16, 2018

Unfortunately, this is likely docker/for-win#445, and there's not really anything we can do to fix it directly in the image. You might be able to work around it by messing with --user (user: in the compose YAML), but there are some caveats to that noted in https://hub.docker.com/_/postgres/.

@matthewfieger
Copy link

Are there any updates on this issue? Here is a simple case to produce this error:

Compose file:

version: "3.7"
services:
  postgres-test:
    restart: always
    image: postgres:latest
    ports:
      - "5432:5432"
    environment:
      - PGDATA=/var/lib/postgresql/data/pgdata
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=postgres
    volumes:
      - ./postgres/data:/var/lib/postgresql/data/pgdata

Docker file:

FROM postgres:11.5-alpine
RUN mkdir -p "$PGDATA" && chmod -R 700 "$PGDATA" && chown -R postgres:postgres "$PGDATA"

I tried 1) changing the location of the data folder 2) running as root and 3) changing the ownership of the data folder. I can't use a named volume as others have suggested because I need to mount the data folder to a specific location on my server.

@yami12376
Copy link

I have the same issue running:
docker run --name some-postgres -v E:\tmp\postgresBaza:/var/lib/postgresql/data -d postgres:9.6.15

I get from logs:

FATAL: data directory "/var/lib/postgresql/data" has wrong ownership

@netsrotr
Copy link

Maybe there is a way to get around this using the userns-remap on the deamon? Must the docker image be "prepared" to use that feature?

@reinierkors
Copy link

I solved this by mapping my local volume one directory below the one Postgres needs:

version: '3'
services:
  postgres:
    image: postgres
    restart: on-failure
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password
      - PGDATA=/var/lib/postgresql/data/pgdata
      - POSTGRES_DB=postgres
    volumes:
      - ./postgres_data:/var/lib/postgresql
    ports:
      - 5432:5432

@PaulMEdwards
Copy link

This solution worked for me:

docker/for-win#445 (comment)

@robinhli
Copy link

I have same issue with official image on windows 10. even I set up the PGDATA to a lower level subdirectory as :
docker run -d -e POSTGRES_USER=xxxx-e POSTGRES_PASSWORD=xxxx-e POSTGRES_DB=postgres -e PGDATA=/var/lib/postgresql/data/pgdata -p 5433:5432 -v /D/PostgreSQL/DockerData:/var/lib/postgresql/data --name db postgres

@hgoo150925
Copy link

I solved this by mapping my local volume one directory below the one Postgres needs:

version: '3'
services:
  postgres:
    image: postgres
    restart: on-failure
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password
      - PGDATA=/var/lib/postgresql/data/pgdata
      - POSTGRES_DB=postgres
    volumes:
      - ./postgres_data:/var/lib/postgresql
    ports:
      - 5432:5432

Thank U!! I solve my problem

@sg552
Copy link

sg552 commented Jan 5, 2023

I met this problem when:

  1. I run windows docker using wsl-2 mode
  2. then I re-installed windows docker using 'wsl-1mode with existing files which is generated bywsl-2` model.

switch to wsl-2 solved my problem.

图片

@fincentxyz
Copy link

Any updates on this issue? I'm trying to deploy a Postgresql Docker container in Microsoft Azure. Their YAML file doesn't have the ability to use named volumes as far as I can tell. When I'm using azureFile, which is basically a bind mount, I stumble upon this issue as well...

@riclovato
Copy link

I solved this by mapping my local volume one directory below the one Postgres needs:

version: '3'
services:
  postgres:
    image: postgres
    restart: on-failure
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password
      - PGDATA=/var/lib/postgresql/data/pgdata
      - POSTGRES_DB=postgres
    volumes:
      - ./postgres_data:/var/lib/postgresql
    ports:
      - 5432:5432

it worked for me. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests