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.
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)
container_name: postgresql
image: postgres:latest
environment:
POSTGRES_PASSWORD: postgres
# volumes:
# - "./database:/var/lib/postgresql/data/"
ports:
- "5432:5432"
Comment the volumes
This work around did the trick and worked on windows, i have to bring those two lines back on mac but that's the easiest way to work for now until some real solution get pushed by docker windows or posgres docker
Related
I have the follow code of my docker-compose.yml:
version: '3'
services:
db:
image: postgres:14.6
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- ./data:/var/lib/postgresql/data
But when I do docker compose up, the console give me the next error:
servicios-basesdatos-db-1 exited with code 1
servicios-basesdatos-db-1 | The files belonging to this database system will be owned by user "postgres".
servicios-basesdatos-db-1 | This user must also own the server process.
servicios-basesdatos-db-1 |
servicios-basesdatos-db-1 | The database cluster will be initialized with locale "en_US.utf8".
servicios-basesdatos-db-1 | The default database encoding has accordingly been set to "UTF8".
servicios-basesdatos-db-1 | The default text search configuration will be set to "english".
servicios-basesdatos-db-1 |
servicios-basesdatos-db-1 | Data page checksums are disabled.
servicios-basesdatos-db-1 |
servicios-basesdatos-db-1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
servicios-basesdatos-db-1 | creating subdirectories ... ok
servicios-basesdatos-db-1 | selecting dynamic shared memory implementation ... posix
servicios-basesdatos-db-1 | selecting default max_connections ... 20
servicios-basesdatos-db-1 | selecting default shared_buffers ... 400kB
servicios-basesdatos-db-1 | selecting default time zone ... Etc/UTC
servicios-basesdatos-db-1 | creating configuration files ... ok
servicios-basesdatos-db-1 | 2023-01-31 09:07:54.976 UTC [83] FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
servicios-basesdatos-db-1 | 2023-01-31 09:07:54.976 UTC [83] HINT: The server must be started by the user that owns the data directory.
servicios-basesdatos-db-1 | child process exited with exit code 1
servicios-basesdatos-db-1 | initdb: removing contents of data directory "/var/lib/postgresql/data"
And I can't up my docker.
How can I fix it so that it works?
Think this line is crucial here
servicios-basesdatos-db-1 | 2023-01-31 09:07:54.976 UTC [83] FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
You may try this solution (initialization of volume in volumes) like:
version: '2'
services:
db:
image: postgres:14.6
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres:
If you look at the docker file if the image here https://github.com/docker-library/postgres/blob/41bd7bf3f487e6dc0036fd73efaff6ccb6fbbacd/14/bullseye/Dockerfile you'll see that they create a user with id 999.
I guess your local data directory is owned by you, which is in most cases user 1000.
So if you chown the data directory to user 999, it should work.
I'm trying to spin up a postgresl database using docker compose on my mac running macOS 12.4.
My docker-compose.yml file is
version: '3.8'
services:
db:
image: postgres:latest
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: gymbro
ports:
- 5438:5432
volumes:
- ./pgdata:/var/lib/postgresql/data
Running docker-compose up results in the container exiting with status 1. Here is the relevant output
Attaching to docker-compose-gymbro-db-1
docker-compose-gymbro-db-1 | The files belonging to this database system will be owned by user "postgres".
docker-compose-gymbro-db-1 | This user must also own the server process.
docker-compose-gymbro-db-1 |
docker-compose-gymbro-db-1 | The database cluster will be initialized with locale "en_US.utf8".
docker-compose-gymbro-db-1 | The default database encoding has accordingly been set to "UTF8".
docker-compose-gymbro-db-1 | The default text search configuration will be set to "english".
docker-compose-gymbro-db-1 |
docker-compose-gymbro-db-1 | Data page checksums are disabled.
docker-compose-gymbro-db-1 |
docker-compose-gymbro-db-1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
docker-compose-gymbro-db-1 | creating subdirectories ... ok
docker-compose-gymbro-db-1 | selecting dynamic shared memory implementation ... posix
docker-compose-gymbro-db-1 | selecting default max_connections ... 100
docker-compose-gymbro-db-1 | selecting default shared_buffers ... 128MB
docker-compose-gymbro-db-1 | selecting default time zone ... Etc/UTC
docker-compose-gymbro-db-1 | creating configuration files ... ok
docker-compose-gymbro-db-1 | running bootstrap script ... ok
docker-compose-gymbro-db-1 | performing post-bootstrap initialization ... 2022-12-24 17:42:20.791 UTC [40] FATAL: data directory "/var/lib/postgresql/data" has invalid permissions
docker-compose-gymbro-db-1 | 2022-12-24 17:42:20.791 UTC [40] DETAIL: Permissions should be u=rwx (0700) or u=rwx,g=rx (0750).
docker-compose-gymbro-db-1 | child process exited with exit code 1
docker-compose-gymbro-db-1 | initdb: removing contents of data directory "/var/lib/postgresql/data"
docker-compose-gymbro-db-1 exited with code 1
Seems like there is a permissions issue,
docker-compose-gymbro-db-1 | performing post-bootstrap initialization ... 2022-12-24 17:42:20.791 UTC [40] FATAL: data directory "/var/lib/postgresql/data" has invalid permissions
docker-compose-gymbro-db-1 | 2022-12-24 17:42:20.791 UTC [40] DETAIL: Permissions should be u=rwx (0700) or u=rwx,g=rx (0750).
I can spin up the db using a docker volume, but I'm just curious as to why this is happening and if there is a possible solution.
On Linux here, so this might not work on Mac. However, why not avoid using the local volum?
Like:
version: '3'
services:
db:
image: postgres:13.2
env_file:
- .env
volumes:
- data:/var/lib/postgresql/data
volumes:
data: {}
This is a solution I always use and solved my issues once and for all when I used to have it.
However, there is a more interesting discussion on this here that you can go through: https://forums.docker.com/t/data-directory-var-lib-postgresql-data-pgdata-has-wrong-ownership/17963/22
I have seen some items I honestly won't recommend like changing the PG_DATA, but if you're comfortable with it, have a go.
Let me know what you think :)
On Docker Desktop (Windows 10), i'm unable to start postgres container with docker-compose
version: '3'
services:
postgres:
image: postgres:latest
environment:
- POSTGRES_PASSWORD='somepassword'
- POSTGRES_HOST_AUTH_METHOD=trust
Getting error that password is not set:
$ docker-compose up --build
Starting complex_postgres_1 ... done
Attaching to complex_postgres_1
postgres_1 | Error: Database is uninitialized and superuser password is not specified.
postgres_1 | You must specify POSTGRES_PASSWORD to a non-empty value for the
postgres_1 | superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
postgres_1 |
postgres_1 | You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
postgres_1 | connections without a password. This is *not* recommended.
postgres_1 |
postgres_1 | See PostgreSQL documentation about "trust":
postgres_1 | https://www.postgresql.org/docs/current/auth-trust.html
complex_postgres_1 exited with code 1
However, on Linux (CentOS 8) all works fine, even without last line - POSTGRES_HOST_AUTH_METHOD=trust
Has anyone experienced same issue on Windows 10 ?
Docker desktop is on latest version as well as docker-compose command
The single quote in your password is also going as a part of password
version: '3'
services:
postgres:
image: postgres:latest
environment:
- POSTGRES_PASSWORD=somepassword
- POSTGRES_HOST_AUTH_METHOD=trust
I have a docker compose file where i am launching PostgreSQL with shared volume. But i am continuously getting the bellow ERROR.
2018-10-11 14:57:01.757 GMT [81] LOG: skipping missing configuration
file "/postgresql/data/postgresql.auto.conf"
| 2018-10-11 14:57:01.768 GMT [81] FATAL: data directory "/postgresql/data" has wrong ownership
| 2018-10-11 14:57:01.768 GMT [81] HINT: The server must be started by the user that owns the data directory.
My docker compose file as below
addb:
image : postgres
networks:
- private
ports:
- "5432:5432"
volumes:
- /mnt/shared/app_data/db/postgres/data_db:/postgresql/data
depends_on:
- sol-server
I am using RHEL 7.5 and Docker version 18.06.1-ce, build e68fc7. Any Idea how i can resolve the above issue.
You should mount your volume with the database in /var/lib/postgresql/data
instead of /postgresql/data or give a enviroment PGDATA=/postgresql/data
1: docker-compose.yml
postgres96:
image: postgres:9.6
ports:
- "5432:5432"
volumes:
- ./Postgres/data:/var/lib/postgresql/data
env:
POSTGRES_PASSWORD: admin#123
POSTGRES_USER: postgres
2) $ docker-compose up &
postgres96_1 | LOG: database system was not properly shut down; automatic recovery in progress
postgres96_1 | LOG: invalid record length at 0/1570D50: wanted 24, got 0
postgres96_1 | LOG: redo is not required
postgres96_1 | LOG: MultiXact member wraparound protections are now enabled
postgres96_1 | LOG: database system is ready to accept connections
postgres96_1 | LOG: autovacuum launcher started
But while testing from pg-admin-iv on windows it show that 'user postgress has no password',
So is that flow from YML file is right, i want simply up the postgress and put data out side docker-container, so How to achieve this?
I would use named volumes for that instead of hosted mapped volumes:
postgres96:
image: postgres:9.6
ports:
- "5432:5432"
volumes:
- data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: admin#123
POSTGRES_USER: postgres
Probably you have a permission issue in your folder.
You data is saved in a volume outside the container. Then check with:
docker volume ls
Also use docker-compose as:
docker-compose up -d
Instead of &
And
docker-compose logs -f
For further information this is the last part of my log:
postgres96_1 | PostgreSQL init process complete; ready for start up.
postgres96_1 |
postgres96_1 | LOG: database system was shut down at 2016-11-14 21:05:51 UTC
postgres96_1 | LOG: MultiXact member wraparound protections are now enabled
postgres96_1 | LOG: database system is ready to accept connections
postgres96_1 | LOG: autovacuum launcher started
postgres96_1 | LOG: incomplete startup packet
Regards