3

I have a data container with Dockerfile:

from ubuntu:latest

VOLUME ["/var/lib/postgresql/9.3/main"]

and a postgresql service container:

#install stuff
............

# Set the default command to run when starting the container
CMD  ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]

then I start the data container and postgresql container:

docker run -i -t -d --name data docker:data

docker run -i -t -p 49131:5432 --name postgresql --volumes-from data --rm docker:postgresql

it says :

FATAL:  data directory "/var/lib/postgresql/9.3/main" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.

it seems like the /var/lib/postgresql/9.3/main folder belong to the root user in the data container. Then i attach to the container, add user and change owner of that folder to postgres:

docker attach data
useradd postgres -s /bin/bash
chown -R postgres:postgres /var/lib/postgresql

then try again with the same error.

what is the problem and what am i missing?

1 Answer 1

8

The postgres user probably hasn't been assigned the same UID in the separate containers.

There's no need to make it this difficult though, just use the postgres image to create your data container e.g:

docker run --name data-container postgres echo "Data Container"

That way all the permissions will be set up correctly. For more information see:

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

1 Comment

thanks, using the postgresql image solved the problem!

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.