Postgres Docker Image: Failed to map database to host

I’m using the stock official Postgres image from Docker Hub. docker pull postgres. I wanted to map the data directory in the Postgres container to my OS X host. So, I tried this.

docker run --rm -p 5432:5432 -e POSTGRES_PASSWORD=mypass -v `pwd`/data:/var/lib/postgresql/data postgres

This resulted in the Postgres container failing to launch correctly.

  • Jupyter Spark database access; java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
  • Docker for dev and production
  • Docker: Unable to view running container despite successful demo example
  • Setting up a remote interpreter in PhpStorm with docker
  • How to mimic --device option in docker run in kubernetes
  • Docker container binds to port, but I am unable to ping it
  • fixing permissions on existing directory /var/lib/postgresql/data ... ok
    creating subdirectories ... initdb: could not create directory "/var/lib/postgresql/data/global": Permission denied
    initdb: removing contents of data directory "/var/lib/postgresql/data"
    

    The goal I’m trying to achieve is to have my database data stored on the host machine, so that I can start a postgres container and have it read (or load) the database from a previous instance. Am I on the right track or is this a stupid way to achieve database persistence?

  • Jenkins with publish over ssh - unable to migrae server configuration
  • Docker - Couldn't connect to Docker daemon
  • Kubernetes fails to pull Docker image from artifactoryonline.com
  • How to use STOPSIGNAL instruction within Docker?
  • I can't start the docker service with iptables error
  • How can I use a docker swarm mode manager behind a floating IP
  • One Solution collect form web for “Postgres Docker Image: Failed to map database to host”

    According to official documentation you should use boot2docker to resolve the issue. However, without it, you won’t be able to mount container.

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