Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql container not starting: chmod: changing permissions of '/bitnami/postgresql/data': Operation not permitted

bitnami/postgresql is unable to start with volume mount. I am using 10.14.0 version of the official docker image.

Container starts without the volume mount:

docker run --rm --name postgresql -e POSTGRESQL_PASSWORD=password123 bitnami/postgresql:10.14.0

postgresql 16:09:04.59 
postgresql 16:09:04.60 INFO  ==> ** Starting PostgreSQL setup **
postgresql 16:09:04.62 INFO  ==> Validating settings in POSTGRESQL_* env vars..
postgresql 16:09:04.63 INFO  ==> Loading custom pre-init scripts...
postgresql 16:09:04.63 INFO  ==> Initializing PostgreSQL database...
postgresql 16:09:04.66 INFO  ==> pg_hba.conf file not detected. Generating it...
postgresql 16:09:04.66 INFO  ==> Generating local authentication configuration
postgresql 16:09:05.97 INFO  ==> Starting PostgreSQL in background...
postgresql 16:09:06.11 INFO  ==> Changing password of postgres
postgresql 16:09:06.14 INFO  ==> Configuring replication parameters
postgresql 16:09:06.17 INFO  ==> Configuring fsync
postgresql 16:09:06.18 INFO  ==> Loading custom scripts...
postgresql 16:09:06.19 INFO  ==> Enabling remote connections
postgresql 16:09:06.20 INFO  ==> Stopping PostgreSQL...

postgresql 16:09:07.21 INFO  ==> ** PostgreSQL setup finished! **
postgresql 16:09:07.25 INFO  ==> ** Starting PostgreSQL **
2020-09-16 16:09:07.279 GMT [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2020-09-16 16:09:07.279 GMT [1] LOG:  listening on IPv6 address "::", port 5432
2020-09-16 16:09:07.283 GMT [1] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2020-09-16 16:09:07.296 GMT [105] LOG:  database system was shut down at 2020-09-16 16:09:06 GMT
2020-09-16 16:09:07.302 GMT [1] LOG:  database system is ready to accept connections

with volume mount

docker run --rm --name postgresql -v /postgresql:/bitnami/postgresql -e POSTGRESQL_PASSWORD=password123 bitnami/postgresql:10.14.0

postgresql 16:10:05.99 
postgresql 16:10:05.99 Welcome to the Bitnami postgresql container
postgresql 16:10:05.99 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
postgresql 16:10:05.99 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
postgresql 16:10:05.99 
postgresql 16:10:06.01 INFO  ==> ** Starting PostgreSQL setup **
postgresql 16:10:06.02 INFO  ==> Validating settings in POSTGRESQL_* env vars..
postgresql 16:10:06.03 INFO  ==> Loading custom pre-init scripts...
postgresql 16:10:06.03 INFO  ==> Initializing PostgreSQL database...
mkdir: cannot create directory ‘/bitnami/postgresql/data’: Permission denied
postgresql 16:10:06.04 INFO  ==> Stopping PostgreSQL...

with docker-compose file

postgresql:
      image: bitnami/postgresql:10.14.0
      container_name: postgresql
      ports:
        - 5432:5432
      environment: 
        - POSTGRESQL_REPLICATION_MODE=master
        - POSTGRESQL_REPLICATION_USER=repl_user
        - POSTGRESQL_REPLICATION_PASSWORD=repl_password
        - POSTGRESQL_USERNAME=my_user
        - POSTGRESQL_PASSWORD=my_password
        - POSTGRESQL_DATABASE=my_database
        - POSTGRESQL_SYNCHRONOUS_COMMIT_MODE=on
        - POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS=1
      volumes:
        - /postgresql:/bitnami/postgresql
      restart: always

output:

docker-compose up

postgresql      | postgresql 16:12:34.68 
postgresql      | postgresql 16:12:34.68 Welcome to the Bitnami postgresql container
postgresql      | postgresql 16:12:34.68 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
postgresql      | postgresql 16:12:34.68 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
postgresql      | postgresql 16:12:34.68 
postgresql      | postgresql 16:12:34.70 INFO  ==> ** Starting PostgreSQL setup **
postgresql      | postgresql 16:12:34.72 INFO  ==> Validating settings in POSTGRESQL_* env vars..
postgresql      | postgresql 16:12:34.72 INFO  ==> Loading custom pre-init scripts...
postgresql      | postgresql 16:12:34.73 INFO  ==> Initializing PostgreSQL database...
postgresql      | chmod: changing permissions of '/bitnami/postgresql/data': Operation not permitted
postgresql      | postgresql 16:12:34.74 WARN  ==> Lack of permissions on data directory!
postgresql      | chmod: changing permissions of '/bitnami/postgresql/data': Operation not permitted
postgresql      | postgresql 16:12:34.75 WARN  ==> Lack of permissions on data directory!
postgresql      | postgresql 16:12:34.75 INFO  ==> pg_hba.conf file not detected. Generating it...
postgresql      | postgresql 16:12:34.75 INFO  ==> Generating local authentication configuration
postgresql      | postgresql 16:12:34.78 INFO  ==> Stopping PostgreSQL...

I am unable to find any solution to this. other containers don't seem to have this problem. Please help if anyone finds solution to this problem.

like image 912
thecodeboxed Avatar asked Sep 16 '20 16:09

thecodeboxed


People also ask

What is Bitnami PostgreSQL?

About PostgreSQL packaged by Bitnami PostgreSQL (Postgres) is an open source object-relational database known for reliability and data integrity. ACID-compliant, it supports foreign keys, joins, views, triggers and stored procedures. Download virtual machines or run your own postgresql server in the cloud.


Video Answer


1 Answers

Bitnami Engineer here,

As the Bitnami PostgreSQL container is a non-root container, the user with id 1001 needs to have write permissions in the local folder you are mounting.

sudo chown -R 1001:1001 /postgresql

You can find more information about that in our GitHub repository

https://github.com/bitnami/bitnami-docker-postgresql#persisting-your-database

like image 71
Jota Martos Avatar answered Oct 19 '22 17:10

Jota Martos