简体   繁体   English

如何使用 Docker 运行 PostgreSQL

[英]How to Run PostgreSQL by using Docker

Goal:目标:
Run Postgres in docker by pulling postgres from docker hub ( https://hub.docker.com/_/postgres ) Run Postgres in docker by pulling postgres from docker hub ( https://hub.docker.com/_/postgres )

Background:背景:
I get a message when I tried running docker with postgres当我尝试使用 postgres 运行 docker 时收到一条消息

Error: Database is uninitialized and superuser password is not specified.
You must specify POSTGRES_PASSWORD to a non-empty value for the
superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".

I got info at https://andrew.hawker.io/dailies/2020/02/25/postgres-uninitialized-error/ about why.我在https://andrew.hawker.io/dailies/2020/02/25/postgres-uninitialized-error/获得了有关原因的信息。

Problem:问题:
"Update your docker-compose.yml or corresponding configuration with the POSTGRES_HOST_AUTH_METHOD environment variable to revert back to previous behavior or implement a proper password." “使用 POSTGRES_HOST_AUTH_METHOD 环境变量更新您的 docker-compose.yml 或相应配置,以恢复到以前的行为或实施正确的密码。” ( https://andrew.hawker.io/dailies/2020/02/25/postgres-uninitialized-error/ ) https://andrew.hawker.io/dailies/2020/02/25/postgres-uninitialized-error/

I don't understand the solution about how to solve the current situation.我不明白如何解决当前情况的解决方案。
Where can i find the dokcer-compose.yml?我在哪里可以找到 dokcer-compose.yml?

Info:信息:
*I'm newbie in PostGre and Docker *我是 PostGre 和 Docker 的新手

If you need to run PostgreSQL in docker you will have to use a variable in docker run command like this:如果您需要在 docker 中运行 PostgreSQL ,则必须在 docker 中使用变量,运行命令如下:

$ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres

The error is telling you the same.错误告诉你同样的。 Read more at https://hub.docker.com/_/postgreshttps://hub.docker.com/_/postgres了解更多信息

Docker-compose.yml is just another option. Docker-compose.yml 只是另一种选择。 You can run it just by docker run like in first answer.您可以像第一个答案一样运行 docker 来运行它。 If you want use docker-compose, in documentation is example of it:如果你想使用 docker-compose,在文档中就是它的例子:

stack.yaml堆栈.yaml

version: '3.1'

services:

  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: example

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

and run: docker-compose -f stack.yml up .并运行: docker-compose -f stack.yml up Everything is here: https://hub.docker.com/_/postgres一切都在这里: https://hub.docker.com/_/postgres

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM