带有外部数据容器的Docker postgresql容器

带有外部数据容器的Docker postgresql容器,postgresql,docker,Postgresql,Docker,我有一个带有Dockerfile的数据容器: from ubuntu:latest VOLUME ["/var/lib/postgresql/9.3/main"] 以及postgresql服务容器: #install stuff ............ # Set the default command to run when starting the container CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/

我有一个带有Dockerfile的数据容器:

from ubuntu:latest

VOLUME ["/var/lib/postgresql/9.3/main"]
以及postgresql服务容器:

#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"]
然后启动数据容器和postgresql容器:

#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"]
docker run-i-t-d——名称数据docker:data

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

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.
似乎
/var/lib/postgresql/9.3/main
文件夹属于
数据
容器中的root用户。然后我附加到容器,添加用户并将该文件夹的所有者更改为postgres:

docker attach data
useradd postgres -s /bin/bash
chown -R postgres:postgres /var/lib/postgresql
然后再试一次,出现同样的错误


问题出在哪里?我遗漏了什么?

postgres用户可能没有在单独的容器中分配相同的UID

不过,无需如此困难,只需使用postgres图像创建数据容器即可,例如:

docker run --name data-container postgres echo "Data Container"
这样,所有权限都将正确设置。有关更多信息,请参阅:


谢谢,使用postgresql映像解决了问题!