2

I've been running my docker images upon my Vagrant machine (the box is ubuntu 14.04) without any big issues. But the following error is racking my brains. I wish you people can help me.

When I run this:

$ docker run -it -v /vagrant/postgresql/data:/var/lib/postgresql/data postgres:9.2

I get this error

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

fixing permissions on existing directory /var/lib/postgresql/data ... ok
initdb: could not create directory "/var/lib/postgresql/data/pg_xlog": Permission denied
initdb: removing contents of data directory "/var/lib/postgresql/data"
vagrant@legionat:/vagrant/sonarqube$ docker run -it -v /vagrant/postgresql/data:/var/lib/postgresql/data postgres:9.2
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

fixing permissions on existing directory /var/lib/postgresql/data ... ok
initdb: could not create directory "/var/lib/postgresql/data/pg_xlog": Permission denied
initdb: removing contents of data directory "/var/lib/postgresql/data"

I've tried open all the permissions of /vagrant/postgresql without success. Maybe this is a problem of the official docker image.

EDIT:

I've just noticed that that is a lot of people facing the same problem as me: https://github.com/docker-library/postgres/issues/26

And, as someone asked about this in the comments, here it goes:

$ ls -l /vagrant/postgresql/data
total 0
2
  • 1
    What OS is your host machine? I'm assuming /vagrant is mounted into the VM from there? Can you post the output of ls -l /vagrant/postgresql/data inside the VM? Commented Oct 1, 2016 at 20:20
  • @sprkysnrky edited! Commented Oct 1, 2016 at 20:28

2 Answers 2

4

If you are just concerned about persisting the data, I would recommend using a data volume instead of a host volume.

Run docker volume create --name pgdata Then connect it to your container with: docker run --rm --name pg -v pgdata:/var/lib/PostgreSQL/data postgres:9.2

Even after that container is gone, you can start a new one connected to the volume and your data will be there.

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

Comments

0

Just make sure your Vagrant user has the permission to access this directory:

ls -ld /vagrant/postgresql/data

And as deinspanjer said. you can use named volume for persisting the data

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.