Postgresql with docker: FATAL: could not read permissions of directory: Permission denied

I’m trying to dockerize a postgresql server while persisting the data on the host. My container works fine without mounting volumes from the host, but it crashes because of permissions with those volumes:

FATAL: could not read permissions of directory "/var/lib/postgresql/9.4/main": Permission denied

  • Pushing a tag to private docker registry in artifactory fails from mac
  • Docker Hub automated build failure. Local build is fine
  • How to make the external host IP address assigned to container hostname?
  • Docker cannot remove all images
  • Start docker-machine On Boot
  • permission error on executing docker run
  • my docker run command is

    docker run -p 54332:5432 -v `pwd`/volumes/postgres/log:/var/log/postgresql -v `pwd`/volumes/postgres/lib:/var/lib/postgresql mypostgres`
    

    and my docker file:

    FROM ubuntu:trusty
    
    RUN apt-get update && \
        apt-get install wget --assume-yes
    
    RUN echo "deb http://apt.postgresql.org/pub/repos/apt trusty-pgdg main" >> /etc/apt/sources.list &&\
        wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
    
    RUN apt-get update &&\
        apt-get install postgresql-9.4-postgis-2.1 postgresql-contrib --assume-yes
    
    RUN mkdir /home/postgres/  && \
        chown -R postgres /home/postgres
    
    USER postgres
    
    # make .pgpass file
    RUN echo "127.0.0.1:5432:database:username:password" >> /home/postgres/.pgpass
    
    RUN /etc/init.d/postgresql start &&\
        psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\
        createdb -O docker docker
    
    # Adjust PostgreSQL configuration so that remote connections to the
    # database are possible. 
    RUN echo "host all  all    0.0.0.0/0  md5" >> /etc/postgresql/9.4/main/pg_hba.conf
    
    RUN echo "listen_addresses='*'" >> /etc/postgresql/9.4/main/postgresql.conf
    
    # Expose the PostgreSQL port
    EXPOSE 5432
    
    # Add VOLUMEs to allow backup of config, logs and databases
    VOLUME  ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
    
    # Set the default command to run when starting the container
    CMD ["/usr/lib/postgresql/9.4/bin/postgres", "-D", "/var/lib/postgresql/9.4/main", "-c", "config_file=/etc/postgresql/9.4/main/postgresql.conf"]
    

  • How to save application state in Marathon?
  • docker python: committed changes in a container but new image does not run
  • Map public container port for few private in Rancher
  • docker stop && docker rm doesn't really get rid of my container
  • How is it possible for two identical Docker images to have different packages installed?
  • How does docker compare to openshift?
  • One Solution collect form web for “Postgresql with docker: FATAL: could not read permissions of directory: Permission denied”

    This happens because:

    • you are on Windows running a VirtualBox VM, itself running the docker host
    • you are mounting a docker volume for a directory which is shared between Windows and the docker host

    Try this:

    docker run -p 54332:5432 -v /tmp/volumes/postgres/log:/var/log/postgresql -v /tmp/volumes/postgres/lib:/var/lib/postgresql mypostgres
    

    it should work as /tmp is not a path shared by VirtualBox with the Windows host.

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