在Dockerfile中创建一个新的PostgreSQL用户

时间:2016-10-25 00:48:01

标签: postgresql docker

我需要为我在Docker图片中构建的PostgreSQL实例创建一个新的超级用户。我似乎无法创建一个,这是我迄今为止尝试过的......

尝试使用“postgres”用户

创建新的超级用户
RUN /etc/init.d/postgresql start &&\
    sudo su - postgres &&\
    sudo psql -U postgres --command "CREATE USER pybossa WITH SUPERUSER PASSWORD 'tester';" &&\
    createdb pybossa -O pybossa


> * Starting PostgreSQL 9.3 database server
>   ...done.
>psql: FATAL:  Peer authentication failed for user "postgres"

“postgres”用户默认没有密码,所以我传入--no-password

RUN /etc/init.d/postgresql start &&\
    sudo su - postgres &&\
    sudo psql -U postgres --no-password --command "CREATE USER pybossa WITH SUPERUSER PASSWORD 'tester';" &&\
    createdb pybossa -O pybossa


> * Starting PostgreSQL 9.3 database server
>   ...done.
>psql: FATAL:  Peer authentication failed for user "postgres"

所以我传递-h localhost以禁用每个身份验证

RUN /etc/init.d/postgresql start &&\
    sudo su - postgres &&\
    sudo psql -U postgres -h localhost --command "CREATE USER pybossa WITH SUPERUSER PASSWORD 'tester';" &&\
    createdb pybossa -O pybossa

> * Starting PostgreSQL 9.3 database server
>   ...done.
>Password for user postgres:
>psql: fe_sendauth: no password supplied

最后,我尝试使用--no-password-h localhost

RUN /etc/init.d/postgresql start &&\
    sudo su - postgres &&\
    sudo psql -U postgres --no-password -h localhost --command "CREATE USER pybossa WITH SUPERUSER PASSWORD 'tester';" &&\
    createdb pybossa -O pybossa

> * Starting PostgreSQL 9.3 database server
>   ...done.
>psql: fe_sendauth: no password supplied

非常感谢任何帮助!

0 个答案:

没有答案