始めに
Markdown 形式で書いたドキュメントをちゃんと整形されてる状態で見るためのツールが欲しいなぁと思い、いろいろ探していた。
Sublime Text 3 の Markdown Extended プラグインのプレビューでもいいのだけど、Qiita とか Git とかのプレビューと微妙に違うのが、ちょっと気にくわなかった。
探している中で、Git のプライベートリポジトリに突っ込んでる方がいて、なるほど~と感心して、探す方向性をプライベートリポジトリとかプライベートWikiに変更したところ、Crowi を推している記事を見かけた。
Markdownで書ける、よさげなWikiサーバーソフトまとめ - Qiita
しかもこの方、Docker Image まで作っている。
ちょうど Docker の勉強をしようと思っていたので即決。
本エントリは、Docker 初心者の私が Crowi を構築したっていうメモ。
環境
Azure 上に CentOS の Virtual Machine を建てて、そこに Docker Container として Crowi を立ち上げた。
Azure Virtual Machine の作成手順は割愛。
$ uname -r
3.10.0-514.2.2.el7.x86_64
$ cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
7.2 のイメージで作成したけど、yum update
したら 7.3 に上がった。
まぁいいか。
手順
- Docker Engine のインストール
- Docker Group の作成
- Docker Compose のインストール
- Docker Crowi の立ち上げ
- Docker Crowi の自動起動設定
1. Docker Engine のインストール
参考
Install Docker on CentOS - Docker
cURL コマンドにて。
$ curl -fsSL https://get.docker.com/ | sudo sh
サービスの状態を確認。
$ sudo systemctl status docker.service
Loaded:
のところで disabled;
になっていたら、自動開始するように設定。
$ sudo systemctl enable docker.service
enabled;
になっていることを確認。
$ sudo systemctl status docker.service
起動。
$ sudo systemctl start docker
Hello World Container を実行してみる。
$ sudo docker run --rm hello-world
こんなのが出力されれば OK だと思う。
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker Hub account:
https://hub.docker.com
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
2. Docker Group の作成
インストールした時点で、グループ自体は作成されるっぽいけど書いておく。
$ sudo groupadd docker
groupadd: group 'docker' already exists # 既に存在した(インストール時に作られた?)ので、怒られた。
Azure Virtual Machine だと VM 作成時に作るユーザーが実質 ROOT だけども、毎回 sudo
やら sudo -s
やらやるのは億劫なので、Group にユーザーを追加。
$ sudo usermod -aG docker [your_username]
一旦ログオフして、再ログイン。
sudo
指定無しで docker run
できることを確認。
$ docker run --rm hello-world
3. Docker Compose のインストール
参考
Install Docker Compose - Docker
Docker の勉強のためには、MongoDB や Redis 、Elasticsearch の Container を自分で作った方がいいのだろうけど、Crowi Image の作者が YAML まで用意してくれているので Docker Compose を使う。
cURL コマンドにて。
注)エントリ公開時点での最新 Release 版を利用。
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.9.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
実行できるように。
$ sudo chmod +x /usr/local/bin/docker-compose
インストール確認。
$ docker-compose --version
(オプション)Docker Compose コマンドを Tab 補完できるようにする
$ sudo curl -L "https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/bash/docker-compose" -o /etc/bash_completion.d/docker-compose
4. Docker Crowi の立ち上げ
作者の Git リポジトリから必要なファイルを頂戴する。ありがたや。
私はダウンロードして転送するのが面倒だったのでクローンした。
$ git clone https://github.com/Bakudankun/docker-crowi.git
Dockerfile
と docker-entrypoint.sh
を Working Dir にコピーする。
README.md
に書いてある YAML ファイルを作る。
内容は完全コピペで動いた。さすが。
$ vi docker-compose.yml
同一ディレクトリに以下3ファイルがある状態にする。
Dockerfile
docker-entrypoint.sh
docker-compose.yml
いざ、立ち上げ。
$ docker-compose up
エラー等無く、途中で出力が止まったら起動出来ているはず。
ブラウザでいざアクセス。( http://[server-ip]:8080/ )
ユーザー新規登録画面が出てくれば OK 。
(URL が http://[server-ip]:8080/install になっているはず)
Azure 的な話をすると、NSG で 8080 に対して穴を開けておくと、Public IP でアクセスできる。
Public IP の Allocation Method が Static なら FQDN を指定できるので、この FQDN でもアクセスできる。
コンソールに戻り、Ctrl + C
で一旦停止。
5. Docker Crowi の自動起動設定
今の状態だと、VM を再起動しても Crowi は立ち上がらないので、自動起動させる。
参考
CentOS7でDockerコンテナの自動起動 - Qiita
自動起動用のサービスを作ってしまおう。
$ sudo sh -c 'cat << EOF > /usr/lib/systemd/system/docker-crowi-autostart.service
[Unit]
Description=Auto start of crowi with docker compose
After=docker.service
Requires=docker.service
[Service]
ExecStart=/usr/local/bin/docker-compose -f [Working Dir Path]/docker-compose.yml up -d
[Install]
WantedBy=multi-user.target
EOF'
サービスを読み込む。
$ sudo systemctl daemon-reload
有効化して、自動起動するように。
$ sudo systemctl enable docker-crowi-autostart.service
そして起動。
$ sudo systemctl start docker-crowi-autostart.service
必要に応じて実際に再起動等して確認を。
Tips
自分がコマンドヘルプをよく見てなかったのが悪いのだけども、止めようと思って docker-compose down
したら削除されてしまって、大変ショックを受けた。
止めるときは kill
・・・。ぼくおぼえた・・・。
まとめ
あまりにもすんなり作れてしまったことに驚いた。
Docker Image や YAML の質がよい証拠。
バクダンくんさん、ありがとうございました。
Crowi 自体はこれからゴリゴリ使い込んで行く。