snippet: docker-compose

* [マニュアル](https://docs.docker.com/compose/compose-file/)
* [最新版](https://docs.docker.com/compose/install/)

```bash:最新版インストール
VERSION=$(curl -sI https://github.com/docker/compose/releases/latest | awk -F'/' '/^Location:/{print $NF}' | tr -d '\r')
URL=https://github.com/docker/compose/releases/download/${VERSION}/docker-compose-`uname -s`-`uname -m`
sh -c "wget -O /usr/local/bin/docker-compose $URL"
chmod +x /usr/local/bin/docker-compose
```

```bash:起動方法
docker-compose up
```

## 参考

* [docker-composeを使うと複数コンテナの管理が便利に - Qiita](http://qiita.com/y_hokkey/items/d51e69c6ff4015e85fce)
* [Dockerで即実行できる、社内・自宅向けオープンソースWebアプリ - Qiita](http://qiita.com/y_hokkey/items/406b5a8c4bc15354d069#gitbucket)

## docker-compose.ymlの書き方

```bash:commandで複数コマンドを書く方法
  command: sh -c "bundle install && rails s -p 3000 -b '0.0.0.0'"
```

```bash:WORKDIR指定
  working_dir: /app
```

```bash:VOLUMES指定
  volumes:
    - ./app:/app
```

* app:/appでは警告でる

## コンテナ内のデータバックアップ

```bash:docker-backup.sh
#!/bin/sh
set -eu
if [ ! $# -eq 3 ];then
  echo "$0 CONTAINER_NAME tar_name DIRECTORY"
  exit 1
fi

set -x
docker run --rm \
  --volumes-from $1 \
  -v $(pwd):/backup \
  busybox tar cf /backup/$2 $3
```

---

```bash:コンテナ起動
$ docker run -it 0808b6baff6f /bin/bash
root@6f0bdd0513b9:/app# exit
```

```bash:コンテナの名前確認
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS PORTS               NAMES
6f0bdd0513b9        0808b6baff6f        "/bin/bash"         2 seconds ago       Exited (0) 1 seconds ago   serene_fermat
```

* serene_fermat という名前を確認。

```bash:app.tarに固める
$ docker-backup.sh serene_fermat app.tar /app
+ pwd
+ docker run --rm --volumes-from serene_fermat -v /home/tk/work/dockerimage-ja/rails4:/backup busybox tar cf /backup/app.tar /app
tar: removing leading '/' from member names
```

```bash:ホスト側にapp.tarがあることを確認
$ ls -lh app.tar 
-rw-r--r-- 1 root root 92K  9月  7 10:05 app.tar
```

----

## pottava/docker-webui

* [Docker の WebUI 作りました - Qiita](http://qiita.com/pottava/items/2fbdd219274102817a9f)

```bash:docker-compose.yml
docker-webui:
  image: pottava/docker-webui
  restart: always
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
  environment:
    - DOCKER_HOST=unix:///var/run/docker.sock
# ports:
#   - "9000:9000"
```

----

## Codebox (IDE)

* [Docker Hub](https://hub.docker.com/u/codebox/?page=1)
* 以下イメージが用意されている。使用する言語のイメージを指定。

```puppet:docker-compose.yml
data-codebox:
  image: busybox
  restart: always
  volumes:
    - ./data:/workspace
codebox:
  image: 'javierprovecho/docker-codebox'
  restart: always
  ports:
    - 8000:8000
    - 2000:2000
  volumes_from:
    - data-codebox
```

* http://localhost:8000/
  * フォントが小さいので設定から大きくしておく。(12 -> 16)
  * vimキーバインドも用意されている。
  * 使い方よくわからなかったので自分でイメージ作ったほうが早そう


## Libreboard (GTD)

* [demo](https://demo.sandstorm.io/appdemo/m86q05rdvj14yvn78ghaxynqz7u2svw6rnttptxx49g1785cdv1h)

```puppet:docker-compose.yml
manet:
  image: earlyclaim/docker-manet
  restart: always
  ports:
    - "8891:8891"
```

* http://localhost:8891/


## Manet (画面キャプチャ)

* [earlyclaim/docker-Manet](https://github.com/earlyclaim/docker-Manet)

```puppet:docker-compose.yml
manet:
  image: earlyclaim/docker-manet
  restart: always
  ports:
    - "8891:8891"
```

* http://localhost:8891

```bash:使い方
curl "http://localhost:8891/?url=github.com" > github.png
```


## Gitbucket (GIT)

```puppet:docker-compose.yml
data-gitbucket:
  image: busybox
  restart: always
  volumes:
    - ./data:/gitbucket

gitbucket:
  image: f99aq8ove/gitbucket
  restart: always
  volumes_from:
    - data-gitbucket
  ports:
    - "8080:8080"
  command: java -jar /opt/gitbucket.war --prefix=/gitbucket
```

* http://localhost:8080/gitbucket/
  * root : root でログイン
  * http://localhost:8080/gitbucket/root/_ssh にて鍵の登録
  * `ssh root@localhost -p 29418`でssh接続

## Redmine3 (BTS)

* [sameersbn/docker-redmine](https://github.com/sameersbn/docker-redmine)

```yaml:docker-compose.yml
redmine3:
  image: redmine:latest
  restart: always
  volumes:
    - ./sqlite:/usr/src/redmine/sqlite
    - ./files:/usr/src/redmine/files
  ports:
    - "8080:3000"
```

* http://localhost:8080/
  * admin : admin


## owncloud9

* [owncloud](https://hub.docker.com/_/owncloud/)

```yaml:docker-compose.yml
owncloud:
  image: owncloud
  restart: always
  volumes:
    - ./vol/apps:/var/www/html/apps
    - ./vol/config:/var/www/html/config
    - ./vol/data:/var/www/html/data
  ports:
    - "8080:80"
```

* WEBブラウザでアクセスした時、permissionエラーが出る場合は

```bash:コンテナに入って実行
chown -R www-data:www-data /var/ww/html/ 
```

## pydio

* [pydio/pydio-core](https://hub.docker.com/r/pydio/pydio-core/)

```yaml:docker-compose.yml
pydio:
  image: pydio/pydio-core
  restart: always
  ports:
    - "8443:443"
```

* https://localhost:8443/pydio
    * admin : P@ssw0rd

## sshd

* [fedora/ssh](https://hub.docker.com/r/fedora/ssh/)

```yaml:docker-compose.yml
fedora-ssh:
  image: fedora/ssh
  restart: always
  hostname: fedora-ssh
  volumes:
    - .:/home/user/
  ports:
    - "2200:22"
```

```bash:userのパスワード確認(ランダム生成)
$ docker-compose logs
fedora-ssh_1 | ssh user password: hDkyLXrWb+2afpJ80qZY
```

```bash:接続
$ ssh -p 2200 user@localhost
パスワードは hDkyLXrWb+2afpJ80qZY
```

* scpをするには`openssh-clients`パッケージが必要。


## rssh

* [bboehmke/rssh](https://hub.docker.com/r/bboehmke/rssh/)

```yaml:docker-compose.yml
rssh:
  image: bboehmke/rssh
  restart: always
  hostname: rssh
  volumes:
    - .:/home/shareuser/
  ports:
    - "2200:22"
  command: "shareuser::1000:1000"
```

* shareuserをUID:1000,GID:1000で作成。パスワードは空。

```bash:接続確認
sftp -P 2200 shareuser@localhost
```

```bash:ログ確認(接続失敗時のログを確認)
docker-compose logs -f
```

### ssh-keygenをワンライナーで行う

```bash:user1とuser1.pubを作成
ssh-keygen -q -C user1 -f user1 -P P@ssword
```

```bash:空パスワードを指定する場合
ssh-keygen -q -C user1 -f user1 -P ""
```

```bash:ppkに変換する方法(パスワードがからの場合なにも聞かれない)
puttygen user1 -o user1.ppk
```

## wordpress

```yaml:docker-compose.yml 
wordpress:
  image: wordpress
  restart: always
  links:
    - db:mysql
  ports:
    - 8080:80

db:
  image: mariadb
  restart: always
  environment:
    MYSQL_ROOT_PASSWORD: Mu8ain1U
```

* 気に入ったテーマ
    * Generic Framework
* forum
    * bbpress

## zabbix3

* [zabbix-community-docker/docker-compose.yml at master · zabbix/zabbix-community-docker](https://github.com/zabbix/zabbix-community-docker/blob/master/Dockerfile/zabbix-3.0/docker-compose.yml)

```yaml:docker-compose.yml
zabbix-db-storage:
  image: busybox:latest
  restart: always
  volumes:
    - /var/lib/mysql

zabbix-db:
  image: zabbix/zabbix-db-mariadb
  restart: always
  volumes:
    - /backups:/backups
  volumes_from:
    - zabbix-db-storage
  environment:
    - MARIADB_USER=zabbix
    - MARIADB_PASS=my_password

zabbix-server:
  image: zabbix/zabbix-3.0:dev
  restart: always
  ports:
    - "80:80"
    - "10051:10051"
  links:
    - zabbix-db:zabbix.db
  environment:
    - ZS_DBHost=zabbix.db
    - ZS_DBUser=zabbix
        - ZS_DBPassword=my_password
```

* User:pass = Admin/zabbix
* http://localhost/


## Wekan (カンバン)

* [mquandalle/wekan](https://hub.docker.com/r/mquandalle/wekan/)
* [Install Wekan Docker in production · wekan/wekan Wiki](https://github.com/wekan/wekan/wiki/Install-Wekan-Docker-in-production)

```yaml:docker-compose.yml 
wekan:
  image: mquandalle/wekan
  restart: always
  links:
    - wekandb
  environment:
    - MONGO_URL=mongodb://wekandb/wekan
    - ROOT_URL=http://localhost:8081
  ports:
    - 8081:80

wekandb:
   image: mongo
   restart: always
   volumes:
     - ./data:/data/db
```

* http://localhost:8081/

## qbittorrent

```
mkdir config torrents downloads
sudo chown 520 config torrents downloads
sudo chmod o+w config torrents downloads
```

```yaml:docker-compose.yml
qt:
  image: wernight/qbittorrent
  restart: always
  ports:
   - "8080:8080"
   - "6881:6881"
  volumes:
   - ./config:/config
   - ./torrents:/torrents
   - ./downloads:/downloads
```

* http://localhost:8080/

## rainloop

```yaml:docker-compose.yml
rainloop:
  image: ahmet2mir/rainloop
  restart: always
  ports:
   - "8080:80"
```

* http://localhost:8080/?admin
    * admin : 12345


## tinyproxy

```yaml:docker-compose.yml
proxy:
  image: tukiyo3/alpine-tinyproxy
  restart: always
  volumes:
    - ./tinyproxy.conf:/etc/tinyproxy/tinyproxy.conf
  ports:
    - "8888:8888"
```


## samba

* [dperson/samba - Docker Hub](https://hub.docker.com/r/dperson/samba/)
    * [dperson/samba: Samba docker container](https://github.com/dperson/samba)
    * https://github.com/dperson/samba/blob/master/samba.sh
* [Dockerでsambaを構築する方法 | infefl](https://blog.infefl.com/linux/docker/cifs/samba/2018/05/13/Docker%E3%81%A7samba%E3%82%92%E6%A7%8B%E7%AF%89%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95.ja.html)

```sh:run.sh
sudo docker run -it \
 -p 139:139 \
 -p 445:445 \
 -e TZ=JST9 \
 -d dperson/samba \
 \
  -u "user1;passw@rd" \
  -s "share;/share;no;no;no;user1"
# -s "共有名;パス;共有フォルダを見せるか;読み取り専用か;ゲストユーザもアクセスできるか;"
```

```rb:docker-compose.yml
samba:
  image: dperson/samba
  restart: always
  volumes:
    - ./data/:/share/
  ports:
    - 139:139
    - 445:445
  environment:
    - TZ='JST9'
  command: '-u "user1;passw@rd" -s "share;/share;no;no;no;user1"'
```

## gitea

```
version: '3'
services:
  web:
    image: gitea/gitea
    volumes:
      - ./gitea-data:/data
    ports:
      - "3000:3000"
      - "10022:10022"
    environment:
      - TZ=Japan
      - SSH_PORT=10022
    restart: always
```