使用docker的Postgresql:FATAL:无法读取目录的权限:权限被拒绝

时间:2015-06-30 17:26:14

标签: postgresql docker virtualbox

我试图将postgresql服务器停靠,同时在主机上保留数据。我的容器工作正常而没有从主机安装卷,但由于这些卷的权限而崩溃:

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

我的docker run命令是

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

和我的泊坞文件:

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"]

1 个答案:

答案 0 :(得分:0)

这是因为:

  • 您在Windows上运行VirtualBox VM,它本身运行的是docker host
  • 您正在为Windows和Docker主机之间共享的目录安装docker卷

试试这个:

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

它应该工作,因为/tmp不是VirtualBox与Windows主机共享的路径。