توجد مواقع ويب متعددة على خادمي الحالي، PostgreSQL (في Docker) و Redis (أيضًا في Docker). أود إعادة استخدام Postgres و Redis الحاليين مع Discourse.
هذا هو ملف containers/app.yml الخاص بي من Discourse:
templates:
# - "templates/postgres.template.yml"
#- "templates/redis.template.yml"
- "templates/web.template.yml"
## إلغاء التعليق على السطر التالي لتمكين مستمع IPv6
#- "templates/web.ipv6.template.yml"
- "templates/web.ratelimited.template.yml"
## إلغاء التعليق على هذين السطرين إذا كنت ترغب في إضافة Lets Encrypt (https)
#- "templates/web.ssl.template.yml"
#- "templates/web.letsencrypt.ssl.template.yml"
- "templates/web.socketed.template.yml" # تمت الإضافة
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
تعمل مواقع الويب الأخرى بدون دوكر، وهي قادرة على الاتصال بنجاح بـ Redis و PostgreSQL عبر localhost. هذا هو ملف docker-compose من postgres/redis:
version: "1.0"
services:
postgres:
container_name: postgres_db
build: postgres_th
# تمت إزالة بعض الإعدادات لجعل الملف أقصر لهذا المثال
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، أحصل على الخطأ التالي:
./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.
وجدت حلاً هنا Configure Discourse to use a separate PostgreSQL server لاستخدام دوكر مع شبكة المضيف.
./launcher rebuild app --docker-args --net=host --skip-mac-address
وتعيين DISCOURSE_DB_HOST إلى localhost
في هذه الحالة، يعمل كل شيء بشكل جيد، المشكلة الوحيدة المتبقية هي أن صورة Discourse تعمل بدون منفذ مكشوف لأنها تستخدم شبكة المضيف بدلاً من الجسر.
هل هناك أي طريقة للاتصال بخادم Postgres خارجي بطريقة ما دون تعيين صورة دوكر لـ Discourse لاستخدام شبكة المضيف؟ كحل بديل، إذا استخدمت شبكة المضيف، كيف يمكنني توصيل nginx خارجي (يعمل على نفس الخادم ولكن بدون Docker) بـ nginx داخل دوكر Discourse؟