# Discourse/Dockerのインストール

**URL:** <https://forum.ficusonline.com/t/discourse-docker/19>\
**Category:** Server\
**Created:** [2016 年 10 月 5 日午前 9:07 UTC](https://forum.ficusonline.com/t/discourse-docker/19 "2016-10-05T09:07:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)\
**Post date:** [2016 年 10 月 5 日午前 9:07 UTC](https://forum.ficusonline.com/t/discourse-docker/19/1 "2016-10-05T09:07:49Z")

</div>

フォーラムCMSであるDiscourseをインストールする手順について。

> <https://github.com/discourse/discourse/blob/main/docs/INSTALL-cloud.md>

従来のフォーラムCMSであるphpBBからの乗り換えです。Dockerのコンテナとして動作させます。  
既に稼働しているApacheサーバと共存させるため、ポート番号を80以外に指定してインストールします。Apacheのmod\_proxyにより同一グローバルIP内でポート80へのアクセスにはwww.example.com、ポート8088へのアクセスにはwww.example-discouse.comを対応させます。

インストール環境はUbuntu Server 16.04です。

まず初めに以下のライブラリをインストールします。

```auto
$ sudo apt-get install libxml2-dev

```

Apacheのproxyとproxy\_httpモジュールを有効にします。

```auto
$ sudo a2enmod proxy
$ sudo a2enmod proxy_http

```

/etc/apache2/sites-available内にdiscourse.confを作成し下記を記述します。

```auto
<VirtualHost *:80>
  ServerName www.example-discourse.com
  ProxyPass / http://localhost:8088/
  ProxyPassReverse / http://localhost:8088/
</VirtualHost>

```

SeverNameは任意です。  
上記設定を有効にし、Apacheを再起動します。

```auto
$ sudo a2ensite discourse.conf

```

Apacheを再起動します。

```auto
$ sudo service apache2 restart

```

**Docker/Gitのインストール**

下記コマンドでDockerとGitがセットでインストールされます。

```auto
$ sudo wget -qO- https://get.docker.com/ | sh

```

**Discourseのインストール**

```auto
$ sudo -s
# mkdir /var/discourse
# git clone https://github.com/discourse/discourse_docker.git /var/discourse
# cd /var/discourse

```

discourse-setup内で

```auto
check_ports() {
    check_port "8088"
    check_port "443"
    echo "Ports 8088 and 443 are free for use"
}

```

80を8088と書換えてセットアップコマンドを実行します。check\_port "443"は、メインサーバで使用する場合削除して下さい。

```auto
# ./discourse-setup

```

以下の設問への答えを予め用意して下さい。

```auto
    Hostname for your Discourse? [discourse.example.com]: 
    Email address for admin account? [me@example.com]: 
    SMTP server address? [smtp.example.com]: 
    SMTP user name? [postmaster@discourse.example.com]: 
    SMTP port [587]:
    SMTP password? []:

```

containersフォルダ内にapp.ymlが作成されますが、ここでもポートの指定が必要です。

**注意）443ポートをメインサーバで使用する場合、この行は削除します。**

```auto
expose:
  - "8088:80" # http
  - "443:443" # https

```

以下コマンドで再ビルドします。

```auto
# ./launcher rebuild app

```

指定したアドレスを入力すると下記のようなサイトが表示されます。

 ![](https://forum.ficusonline.com/uploads/default/original/1X/51b9f9de4df72630b3b44a14f6ead22d39053285.png)

---

<div class="post-metadata">

**Author:** ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)\
**Post date:** [2016 年 10 月 5 日午後 10:54 UTC](https://forum.ficusonline.com/t/discourse-docker/19/2 "2016-10-05T22:54:50Z")

</div>

Docker上で起動しているDiscourseアプリの起動・停止は以下コマンドとなります。

```auto
$ sudo ./launcher start app
$ sudo ./launcher stop app

```

---

<div class="post-metadata">

**Author:** ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)\
**Post date:** [2017 年 2 月 7 日午前 11:49 UTC](https://forum.ficusonline.com/t/discourse-docker/19/3 "2017-02-07T11:49:21Z")

</div>

Let’s EncryptによるSSL接続に対応させます。

> [@SSL認証Let's Encryptの導入 (Certbot)](https://forum.ficusonline.com/t/ssl-lets-encrypt/20):
>
> 新たな導入環境に合わせ、以前ブログで記述した内容を改訂しています。 Let’s EncryptによるフリーのSSL認証を導入する手順です。 [lets-encrypt] 事前準備 導入環境 Ubuntu Server 16.04 導入前準備として以下項目を再確認・設定して下さい。 Apacheの設定ファイルsite-available内のdefault.confのServerNam…

Let’s Encryptをインストールしたディレクトリに移動します。

> $ cd /opt/letsencrypt

certbot-autoによりApacheのSSL設定ファイル、SSL認証ファイルの作成などを実行します。

> $ sudo certbot --apache -d sub\_domain2.example.com

httpへのアクセスをhttpsへリダイレクトするかどうか以下メッセージが表示されるので番号を入力して下さい。

```
Please choose whether HTTPS access is required or optional.
-------------------------------------------------------------------------------
1: Easy - Allow both HTTP and HTTPS access to these sites
2: Secure - Make all requests redirect to secure HTTPS access
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

```

**参考サイト**

> **[Configure Apache proxy with Let's Encrypt](https://meta.discourse.org/t/configure-apache-proxy-with-lets-encrypt/46139/1)**
>
> ⚠ Using Apache as a proxy is not recommended as Apache Httpd uses thread-per-connection model, and will likely run out of threads very fast as Discourse uses long polling. (related). The goal of this post is to help you set up Let’s Encrypt with...

---

<div class="post-metadata">

**Author:** ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)\
**Post date:** [2019 年 9 月 29 日午前 3:02 UTC](https://forum.ficusonline.com/t/discourse-docker/19/4 "2019-09-29T03:02:16Z")

</div>

### Discourseマニュアルアップデート

試験サーバ：Ubuntu18.04

> **[Manually update Discourse and Docker image to latest](https://meta.discourse.org/t/manually-update-discourse-and-docker-image-to-latest/23325)**
>
> 🔖 This guide provides step-by-step instructions for manually updating Discourse, the Docker container, and the Ubuntu operating system on a self-hosted setup. 🙋 Required user level: System Administrator ⚠ SSH access to the server. If you...

> **[GitHub - discourse/discourse\_docker: A Docker image for Discourse](https://github.com/discourse/discourse_docker)**
>
> A Docker image for Discourse

マニュアルアップデートでエラーが発生した場合、再ビルド・インストール

Docker-CEのアップデートでもエラーが発生したためDocker-CEをマニュアルで再インストール後、コンテナapp、イメージlocal\_discourse/appを削除、app.ymlから再ビルド。

```auto
$ cd /var/discourse
$ sudo ./launcher destroy app
$ sudo git pull
$ sudo ./launcher rebuild app

```

```auto
Usage: launcher COMMAND CONFIG [--skip-prereqs] [--docker-args STRING]
Commands:
    start: Start/initialize a container
    stop: Stop a running container
    restart: Restart a container
    destroy: Stop and remove a container
    enter: Use nsenter to get a shell into a container
    logs: View the Docker logs for a container
    bootstrap: Bootstrap a container for the config based on a template
    rebuild: Rebuild a container (destroy old, bootstrap, start new)
    cleanup: Remove all containers that have stopped for > 24 hours

Options:
    --skip-prereqs Don't check launcher prerequisites
    --docker-args Extra arguments to pass when running docker

```

---

<div class="post-metadata">

**Author:** ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)\
**Post date:** [2021 年 11 月 7 日午前 1:35 UTC](https://forum.ficusonline.com/t/discourse-docker/19/5 "2021-11-07T01:35:56Z")

</div>

**ドメイン変更**

ドメイン名を変更する場合、`app.yml` 内でドメインを変更後、リビルドします。

```auto
$ cd /var/discourse
$ sudo nano containers/app.yml

```

```auto
env:
.....
.....
  DISCOURSE_HOSTNAME: www.example.com
.....
.....

```

リビルド

```auto
$ sudo ./launcher rebuild app

```

---

<div class="post-metadata">

**Author:** ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)\
**Post date:** [2022 年 7 月 16 日午後 2:29 UTC](https://forum.ficusonline.com/t/discourse-docker/19/6 "2022-07-16T14:29:41Z")

</div>

## 他サーバへの移行

> **[Restore a backup from the command line](https://meta.discourse.org/t/restore-a-backup-from-the-command-line/108034)**
>
> 🔖 This guide explains how to restore a Discourse backup from the command line without using the Discourse web UI. 🙋 Required user level: Administrator 🔧 Console access required Here’s how to restore a Discourse backup from the command line,...

移行先サーバで最新版`Discourse`を`git`クローン、バックアップディレクトリを作成

```auto
$ sudo mkdir /var/discourse
$ sudo git clone https://github.com/discourse/discourse_docker.git /var/discourse
$ cd /var/discourse
$ sudo mkdir -p /var/discourse/shared/standalone/backups/default

```

バックアップファイルと `containers/app.yml` を移行先サーバへコピー

```auto
$ sudo scp /path/to/backup/backup.tar.gz root@192.168.1.1:/var/discourse/shared/standalone/backups/default
$ sudo scp /var/discourse/containers/app.yml root@192.168.1.1:/var/discourse/containers

```

* * *

移行先サーバでリビルド

```auto
$ sudo cd /var/discourse
$ sudo ./launcher rebuild app

```

移行先サーバでリストア

```auto
$ sudo ./launcher enter app ---> enter docker container
# discourse enable_restore
# discourse restore sitename-2019-02-03-042252-v20190130013015.tar.gz
# exit

```

**注）** `./launcher enter app` は、下記 `docker exec` コマンドと同義です。

```auto
$ docker exec -ti app bash

```

---

<div class="post-metadata">

**Author:** ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)\
**Post date:** [2025 年 11 月 17 日午前 6:42 UTC](https://forum.ficusonline.com/t/discourse-docker/19/7 "2025-11-17T06:42:26Z")

</div>

## UNIXソケットで接続する場合：app.yml の変更・再ビルド

> **[Installing Discourse Behind Reverse Proxy using recommended (supported)...](https://meta.discourse.org/t/installing-discourse-behind-reverse-proxy-using-recommended-supported-installation/300191?tl=en)**
>
> In this post, I will show you exactly how to run discourse behind a nginx reverse proxy. While still using the supported installation methods. Requirements: Valid domain name. Valid ssl certificate. Valid DNS entries pointing to the domain...

Nginxのリバースプロキシで、接続方法をウェブ接続からUnixソケット接続へ変更

- UNIXソケット対応テンプレートを追加
- exposeをコメントアウト
- HTTPS接続指定

`/var/discourse/containers/app.yml`

```auto
templates:
  - "templates/web.socketed.template.yml"

#expose:
# - "8088:80" # http
# - "443:443" # https

env:
  # FORCE SSL 
  DISCOURSE_FORCE_HTTPS: true

```

Nginxコンテナの設定ファイルで、proxy\_passをUNIXソケット接続に変更。

`/etc/nginx/conf.d/discourse.conf`

```auto
proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;

```

再ビルド

```auto
$ cd /var/discourse
$ sudo ./launcher rebuild app

```

ホストの下記ディレクトリにUNIXソケットが作成されるので、これをNginxコンテナと共有します。

> /var/discourse/shared/standalone/nginx.http.sock

`docker-compose.yml`

```auto
nginx
  .....
  .....
  
  volumes:
    .....
    .....
    - /var/discourse/shared/standalone/nginx.http.sock:/var/discourse/shared/standalone/nginx.http.sock
  .....
  .....

```

> **注）** Unixソケットは、Discourseコンテナ（app）が停止（再起動）すると削除（削除・再作成）されるため、Nginxコンテナと共有する場合は、ソケットが保存されるディレクトリ `/var/discourse/shared/standalone` を共有するか、Discourseコンテナ起動後にNginxコンテナを起動するようにした方がいいかもしれません。
