我正在尝试使用 docker 创建简单的 postgres 服务器。我用官方postgres image作为我的容器的基础。 我的 Dockerfile 包含这些命令:
FROM postgres
USER postgres
RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER user WITH SUPERUSER PASSWORD 'user';" &&\
createdb -O user app
当我尝试运行它时出现错误:
psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
我做错了什么?
最佳答案
postgres 可能需要一些时间才能开始接受连接。按照您编写的方式,它将在 start 函数返回后立即调用 CREATE USER 。尝试在那里睡一觉,看看是否仍然有问题。
关于postgresql - Docker 上的 Postgres。如何创建数据库和用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26201274/