Postgresql raises 'data directory has wrong ownership' when trying to use volume
docker, postgresql
Solution
Ok, seems like I found workaround for this issue.
Instead of running postgres in such way:
CMD ["/usr/lib/postgresql/9.1/bin/postgres", "-D", "/var/lib/postgresql/9.1/main", "-c", "config_file=/etc/postgresql/9.1/main/postgresql.conf"]
I wrote bash script:
chown -Rf postgres:postgres /data/postgresql
chmod -R 700 /data/postgresql
sudo -u postgres /usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf
And replaced CMD in postgresql image to:
CMD ["bash", "/run.sh"]
It works!
Problem
I'm trying to run postgresql in docker container, but of course I need to have my database data to be persistent, so I'm trying to use data only container which expose volume to store database at this place. So, my data container has such Dockerfile: ``` FROM ubuntu # Create data directory RUN mkdir -p /data/postgresql # Create /data volume VOLUME /data/postgresql ``` Which I run: ``` docker run --name postgresql_data lyapun/postgresql_data true ``` In my postgresql.conf I set: ``` data_directory = '/data/postgresql' ``` Then I run my postgresql container in such way: ``` docker run -d --name postgre --volumes-from postgresql_data lyapun/postgresql ``` And I got: ``` 2014-07-04 07:45:57 GMT FATAL: data directory "/data/postgresql" has wrong ownership 2014-07-04 07:45:57 GMT HINT: The server must be started by the user that owns the data directory. ``` How to deal with this issue? I googled a lot to find some information about using postgresql with docker volumes, but I didn't found anything. Thanks!