安装 docker mastodon 时 postgres 不会启动
postgres won't start when installing docker mastodon
我正在尝试安装 mastodon 的 docker 化版本,尽管我已经参考了几个指南(包括官方文档),但我在连接到 postgres 数据库时一直遇到错误。
这里是我的相关部分 docker-compose.yml:
db:
restart: always
image: postgres:9.6-alpine
shm_size: 256mb
networks:
- internal_network
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
volumes:
- ./postgres:/var/lib/postgresql/data
...还有我的 .env.production:
# PostgreSQL
# ----------
DB_HOST=/var/run/postgresql
DB_USER=mastodon
DB_NAME=mastodon_production
DB_PASS=[MY PASSWORD] <--- (I've also tried leaving this blank with no difference in the result)
DB_PORT=5432
但是当我运行(例如):
$ docker-compose run --rm web rails db:migrate
我得到以下输出:
rails aborted!
PG::ConnectionBad: 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"?
和 $ docker logs mastodon_db_1
给我:
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".
You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
connections without a password. This is *not* recommended.
See PostgreSQL documentation about "trust":
https://www.postgresql.org/docs/current/auth-trust.html
我对 docker 比较陌生,但(我认为)我了解基本概念。但是,很多 的谷歌搜索让我认为我是唯一遇到此问题的人而且我看不到我错过了什么。
第二个错误是因为缺少 Postgres 容器所需的 ENV。
Error: Database is uninitialized and superuser password is not specified.
You must specify POSTGRES_PASSWORD to a non-empty value for the
superuser
POSTGRES_PASSWORD
This environment variable is required for you to use the PostgreSQL image. It must not be empty or undefined. This environment variable sets the superuser password for PostgreSQL. The default superuser is defined by the POSTGRES_USER
environment variable
您需要指定POSTGRES_PASSWORD
ENV
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example
POSTGRES_DB: mastodon_production
POSTGRES_USER: mastodon
postgres-docker-Environment Variables
虽然第二个错误似乎主机无效或者您没有正确使用环境变量。
PG::ConnectionBad: could not connect to server: No such file or directory
将点环境文件更改为
DB_HOST=db
DB_USER=mastodon
DB_NAME=mastodon_production
DB_PASS=example <--- (the one which is set in DB)
DB_PORT=5432
DB_HOST 应该是从另一个容器连接到数据库的服务名称。
我正在尝试安装 mastodon 的 docker 化版本,尽管我已经参考了几个指南(包括官方文档),但我在连接到 postgres 数据库时一直遇到错误。
这里是我的相关部分 docker-compose.yml:
db:
restart: always
image: postgres:9.6-alpine
shm_size: 256mb
networks:
- internal_network
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
volumes:
- ./postgres:/var/lib/postgresql/data
...还有我的 .env.production:
# PostgreSQL
# ----------
DB_HOST=/var/run/postgresql
DB_USER=mastodon
DB_NAME=mastodon_production
DB_PASS=[MY PASSWORD] <--- (I've also tried leaving this blank with no difference in the result)
DB_PORT=5432
但是当我运行(例如):
$ docker-compose run --rm web rails db:migrate
我得到以下输出:
rails aborted!
PG::ConnectionBad: 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"?
和 $ docker logs mastodon_db_1
给我:
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".
You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
connections without a password. This is *not* recommended.
See PostgreSQL documentation about "trust":
https://www.postgresql.org/docs/current/auth-trust.html
我对 docker 比较陌生,但(我认为)我了解基本概念。但是,很多 的谷歌搜索让我认为我是唯一遇到此问题的人而且我看不到我错过了什么。
第二个错误是因为缺少 Postgres 容器所需的 ENV。
Error: Database is uninitialized and superuser password is not specified.
You must specify POSTGRES_PASSWORD to a non-empty value for the
superuser
POSTGRES_PASSWORD
This environment variable is required for you to use the PostgreSQL image. It must not be empty or undefined. This environment variable sets the superuser password for PostgreSQL. The default superuser is defined by the
POSTGRES_USER
environment variable
您需要指定POSTGRES_PASSWORD
ENV
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example
POSTGRES_DB: mastodon_production
POSTGRES_USER: mastodon
postgres-docker-Environment Variables
虽然第二个错误似乎主机无效或者您没有正确使用环境变量。
PG::ConnectionBad: could not connect to server: No such file or directory
将点环境文件更改为
DB_HOST=db
DB_USER=mastodon
DB_NAME=mastodon_production
DB_PASS=example <--- (the one which is set in DB)
DB_PORT=5432
DB_HOST 应该是从另一个容器连接到数据库的服务名称。