Docker / Postgres: Mounting an existing database within a dockerized Postgresql

So I’m having a problem mounting an existing set of data for Docker Postgres that I cannot figure out for the life of me. Here’s my docker compose file.

version: '2'
    services:
      postgresql:
        image: postgres:9.5
        environment:
          - PGDATA=/data 
        ports:
      - '5432:5432'
    volumes:
      - ~/.postgresql:/data
  web:
    build: .
    command: sbt/sbt run
    volumes:
      - .:/app
    ports:
      - '9001:9001'
    depends_on:
      - postgresql

Here’s the error I see

  • How do I serve static files from either gunicorn or nginx
  • Docker for Windows does not work with Volumes
  • How do you access the line-in sound card within a docker containder
  • php composer with docker build: failed to clone git
  • Dependent Containers and Links with IBM DevOps Services Build Pipeline
  • Docker swarm over IPv6
  • ostgresql_1 | FATAL:  data directory "/data" has wrong ownership
    postgresql_1 | HINT:  The server must be started by the user that owns the data directory.
    

    Does anyone have any clue how to fix it? Thank you

    PS I am using Docker Machine through OSX if that makes a difference in this problem.

  • How to correctly close a Meteor stream?
  • How can I access both ports 8080 and 9990 on bluemix single container for wildfly?
  • Redis regular timeouts on Docker
  • how do i backup a database in docker
  • Docker API NodeJS
  • Dependency in requirement.txt not installed
  • One Solution collect form web for “Docker / Postgres: Mounting an existing database within a dockerized Postgresql”

    The error message is pretty clear. I think the container runs postgres with user postgres which has a uid/gid of 999 (see https://github.com/docker-library/postgres/blob/3f8e9784438c8fe54f831c301a45f4d55f6fa453/9.5/Dockerfile line 5). You need to chown your host data folder to a user with the same uid.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.