我正在尝试使用这个项目部署一个乳齿象服务器:https://github.com/tootsuite/mastodon
我在Fedora33服务器上运行Docker-Compose和Podman。
$ docker-compose --version
docker-compose version 1.27.4, build unknown
$ docker --version
podman version 3.0.1
$ cat /etc/fedora-release
Fedora release 33 (Thirty Three)我不得不对docker-compose.yml做了一些修改,以使其与Podman一起工作。
version: '3'
services:
db:
restart: always
image: postgres:9.6-alpine
shm_size: 256mb
networks:
- internal_network
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
timeout: 45s
interval: 10s
retries: 10
volumes:
- ./postgres:/var/lib/postgresql/data
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
redis:
restart: always
image: redis:6.0-alpine
networks:
- internal_network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
timeout: 45s
interval: 10s
retries: 10
volumes:
- ./redis:/data
# es:
# restart: always
# image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.10
# environment:
# - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
# - "cluster.name=es-mastodon"
# - "discovery.type=single-node"
# - "bootstrap.memory_lock=true"
# networks:
# - internal_network
# healthcheck:
# test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
# volumes:
# - ./elasticsearch:/usr/share/elasticsearch/data
# ulimits:
# memlock:
# soft: -1
# hard: -1
web:
# build: .
image: tootsuite/mastodon
restart: always
env_file: .env.production
command: bash -c "rm -f /mastodon/tmp/pids/server.pid; bundle exec rails s -p 3000"
networks:
- external_network
- internal_network
healthcheck:
test: ["CMD-SHELL", "wget -q --spider --proxy=off localhost:3000/health || exit 1"]
timeout: 45s
interval: 10s
retries: 10
ports:
- "127.0.0.1:3000:3000"
depends_on:
- db
- redis
# - es
volumes:
- ./public/system:/mastodon/public/system
streaming:
build: .
image: tootsuite/mastodon
restart: always
env_file: .env.production
command: node ./streaming
networks:
- external_network
- internal_network
healthcheck:
test: ["CMD-SHELL", "wget -q --spider --proxy=off localhost:4000/api/v1/streaming/health || exit 1"]
timeout: 45s
interval: 10s
retries: 10
ports:
- "127.0.0.1:4000:4000"
depends_on:
- db
- redis
sidekiq:
build: .
image: tootsuite/mastodon
restart: always
env_file: .env.production
command: bundle exec sidekiq
depends_on:
- db
- redis
networks:
- external_network
- internal_network
volumes:
- ./public/system:/mastodon/public/system
## Uncomment to enable federation with tor instances along with adding the following ENV variables
## http_proxy=http://privoxy:8118
## ALLOW_ACCESS_TO_HIDDEN_SERVICE=true
# tor:
# image: sirboops/tor
# networks:
# - external_network
# - internal_network
#
# privoxy:
# image: sirboops/privoxy
# volumes:
# - ./priv-config:/opt/config
# networks:
# - external_network
# - internal_network
networks:
external_network:
internal_network:
internal: true以下是与存储库中文件的远程版本的不同:
(tl;dr:我向health-checks添加了选项,并添加了一个env变量来授权在没有密码的情况下运行postgres,并注释了build选项以使用repo中的镜像,因为构建也失败了)
$ git diff docker-compose.yml
diff --git a/docker-compose.yml b/docker-compose.yml
index 52eea7a74..a8e047ec7 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -9,8 +9,13 @@ services:
- internal_network
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
+ timeout: 45s
+ interval: 10s
+ retries: 10
volumes:
- ./postgres:/var/lib/postgresql/data
+ environment:
+ - POSTGRES_HOST_AUTH_METHOD=trust
redis:
restart: always
@@ -19,6 +24,9 @@ services:
- internal_network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
+ timeout: 45s
+ interval: 10s
+ retries: 10
volumes:
- ./redis:/data
@@ -42,7 +50,7 @@ services:
# hard: -1
web:
- build: .
+ # build: .
image: tootsuite/mastodon
restart: always
env_file: .env.production
@@ -52,6 +60,9 @@ services:
- internal_network
healthcheck:
test: ["CMD-SHELL", "wget -q --spider --proxy=off localhost:3000/health || exit 1"]
+ timeout: 45s
+ interval: 10s
+ retries: 10
ports:
- "127.0.0.1:3000:3000"
depends_on:
@@ -72,6 +83,9 @@ services:
- internal_network
healthcheck:
test: ["CMD-SHELL", "wget -q --spider --proxy=off localhost:4000/api/v1/streaming/health || exit 1"]
+ timeout: 45s
+ interval: 10s
+ retries: 10
ports:
- "127.0.0.1:4000:4000"
depends_on:生成密钥是可以的,但在执行以下命令时失败:
$ sudo docker-compose run --rm web bundle exec rails db:migrate
Creating network "mastodon_internal_network" with the default driver
Creating network "mastodon_external_network" with the default driver
Creating mastodon_db_1 ... done
Creating mastodon_redis_1 ... done
Creating mastodon_web_run ... done
rails aborted!
PG::ConnectionBad: could not translate host name "db" to address: Name or service not known我已经在几个项目中使用了Docker-Compose和Podman 3.0的组合,并且我在网络内部的主机名解析方面从未遇到过任何问题。我想知道是否必须为这种情况指定驱动程序。
另外,我想要一种方法来测试我是否可以从web容器中使用此主机名访问db服务,因此,如果问题出在代码中(我非常怀疑,但我想确定)。
EDIT1: db服务的日志,显示该服务似乎正在正常运行并准备接受连接
$ sudo docker logs -f mastodon_db_1
PostgreSQL Database directory appears to contain a database; Skipping initialization
LOG: database system was shut down at 2021-04-01 07:02:04 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started发布于 2021-04-10 01:01:57
我找到了一个解决方案:删除网络的定义。
这听起来很便宜,但很管用。
因此,最终的docker-compose.yml如下所示:
version: '3'
services:
db:
restart: always
image: postgres:9.6-alpine
shm_size: 256mb
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
timeout: 45s
interval: 10s
retries: 10
volumes:
- ./postgres:/var/lib/postgresql/data
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
redis:
restart: always
image: redis:6.0-alpine
healthcheck:
test: ["CMD", "redis-cli", "ping"]
timeout: 45s
interval: 10s
retries: 10
volumes:
- ./redis:/data
# es:
# restart: always
# image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.10
# environment:
# - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
# - "cluster.name=es-mastodon"
# - "discovery.type=single-node"
# - "bootstrap.memory_lock=true"
# networks:
# - internal_network
# healthcheck:
# test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
# volumes:
# - ./elasticsearch:/usr/share/elasticsearch/data
# ulimits:
# memlock:
# soft: -1
# hard: -1
web:
# build: .
image: tootsuite/mastodon
restart: always
env_file: .env.production
command: bash -c "rm -f /mastodon/tmp/pids/server.pid; bundle exec rails s -p 3000"
healthcheck:
test: ["CMD-SHELL", "wget -q --spider --proxy=off localhost:3000/health || exit 1"]
timeout: 45s
interval: 10s
retries: 10
ports:
- "127.0.0.1:3000:3000"
depends_on:
- db
- redis
# - es
volumes:
- ./public/system:/mastodon/public/system
streaming:
build: .
image: tootsuite/mastodon
restart: always
env_file: .env.production
command: node ./streaming
healthcheck:
test: ["CMD-SHELL", "wget -q --spider --proxy=off localhost:4000/api/v1/streaming/health || exit 1"]
timeout: 45s
interval: 10s
retries: 10
ports:
- "127.0.0.1:4000:4000"
depends_on:
- db
- redis
sidekiq:
build: .
image: tootsuite/mastodon
restart: always
env_file: .env.production
command: bundle exec sidekiq
depends_on:
- db
- redis
volumes:
- ./public/system:/mastodon/public/system
## Uncomment to enable federation with tor instances along with adding the following ENV variables
## http_proxy=http://privoxy:8118
## ALLOW_ACCESS_TO_HIDDEN_SERVICE=true
# tor:
# image: sirboops/tor
# networks:
# - external_network
# - internal_network
#
# privoxy:
# image: sirboops/privoxy
# volumes:
# - ./priv-config:/opt/config
# networks:
# - external_network
# - internal_networkhttps://stackoverflow.com/questions/66895304
复制相似问题