기존 서버에는 여러 웹사이트, PostgreSQL(Docker 실행) 및 Redis(또한 Docker 실행)가 있습니다. Discourse에서 기존 Postgres와 Redis를 재사용하고 싶습니다.
Discourse의 containers/app.yml 파일은 다음과 같습니다:
templates:
# - "templates/postgres.template.yml"
#- "templates/redis.template.yml"
- "templates/web.template.yml"
## Uncomment the next line to enable the IPv6 listener
#- "templates/web.ipv6.template.yml"
- "templates/web.ratelimited.template.yml"
## Uncomment these two lines if you wish to add Lets Encrypt (https)
#- "templates/web.ssl.template.yml"
#- "templates/web.letsencrypt.ssl.template.yml"
- "templates/web.socketed.template.yml" # Added
extra_hosts:
- "host.docker.internal:host-gateway"
expose:
- "8881:80" # http
# - "443:443" # https
env:
DISCOURSE_DB_NAME: discourse
DISCOURSE_DB_USERNAME: discourse
DISCOURSE_DB_HOST: host.docker.internal
DISCOURSE_DB_PASSWORD: XXXXXXXXXXX
DISCOURSE_REDIS_HOST: host.docker.internal
DISCOURSE_REDIS_PORT: 6379
다른 웹사이트들은 Docker 없이 실행되며, localhost를 통해 Redis와 PostgreSQL에 성공적으로 연결할 수 있습니다. postgres/redis의 docker-compose 파일은 다음과 같습니다:
version: "1.0"
services:
postgres:
container_name: postgres_db
build: postgres_th
# some settings were removed, to make file shorter for this example
ports:
- "5432:5432"
restart: unless-stopped
networks:
- main_network
redis:
container_name: redis
image: redis:7.2.1
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
restart: unless-stopped
networks:
- main_network
networks:
main_network:
external: true
Discourse Docker 이미지를 빌드하려고 하면 다음 오류가 발생합니다:
./launcher rebuild app
FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 358 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}
bootstrap failed with exit code 1
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
Docker를 호스트 네트워크로 사용하도록 설정하는 방법에 대한 해결책을 Configure Discourse to use a separate PostgreSQL server 에서 찾았습니다.
./launcher rebuild app --docker-args --net=host --skip-mac-address
그리고 DISCOURSE_DB_HOST를 localhost로 설정합니다.
이 경우 모든 것이 정상적으로 작동하지만, Discourse 이미지가 브리지 대신 호스트 네트워크를 사용하므로 포트가 노출되지 않는 문제가 남아 있습니다.
Discourse Docker를 호스트 네트워크를 사용하도록 설정하지 않고도 외부 Postgres 서버에 연결할 수 있는 방법이 있을까요? 대안으로, 호스트 네트워크를 사용하는 경우 같은 서버에서 Docker 없이 실행 중인 외부 nginx를 Discourse Docker 내부의 nginx에 어떻게 연결할 수 있을까요?