There are multiple websites on my existing server, PostgreSQL (in Docker) and Redis (also in Docker). I would like to reuse existing Postgres and Redis with Discourse.
Here is my containers/app.yml
from Discourse:
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
Other websites run without docker, and they able to succesfully connect to Redis and PostgreSQL through localhost
. Here is docker-compose file from postgres/redis:
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
When I am trying to build Discourse docker image, I am getting following error:
./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.
I found a solution here Configure Discourse to use a separate PostgreSQL server to use docker with host network.
./launcher rebuild app --docker-args --net=host --skip-mac-address
and setting DISCOURSE_DB_HOST
to localhost
in this case everything works fine, the only problem remains that Discourse image is running without exposed port because it uses host network instead of bridge.
Is there any way to connect to external Postgres server somehow without setting Discourse docker to use host network? As an alternate solution, if I use host network, how do I connect external nginx (which runs on the same server but without Docker) to nginx inside Discourse docker?