---
title: Dockerのホスティングサービス(?)Giant Swarm使ってみた
tags: ["Docker", "Docker Compose", "Giant Swarm"]
categories: ["Dev", "Infrastructure", "Docker", "GiantSwarm"]
date: 2015-05-07T15:59:22Z
updated: 2015-05-24T14:25:04Z
---

![Giant Swarm][1]

[Giant Swarm](https://giantswarm.io/)はDockerホストのようなサービス。Dockerで作ったイメージを運用できる。
[Joyent Triton](https://www.joyent.com/)に似てるサービスかな？

現在、アルファ版でユーザーを[募集中](https://giantswarm.io/request-invite/)。アルファ版は無償で利用できる。
自分は[中の人](https://twitter.com/giantswarm)にメンション送って招待してもらった。

触った感触は、Docker Compose + Docker Swarmをデプロイするようなイメージ。"Docker Compose + Docker Swarm As A Service"？。
`docker-compose.yml`に似た、`swarm.json`で構成を定義して、デプロイする形。個々のインスタンスが別サーバーで起動し、クラスタリングされる模様。

### とりあえずHello World

```
$ brew tap giantswarm/swarm
$ brew install swarm-client
$ git clone https://github.com/giantswarm/helloworld.git
$ cd helloworld
$ swarm login making
$ swarm up --var=domain=helloworld-making.gigantic.io
Creating 'helloworld' in the 'making/dev' environment...
Application created successfully!
Starting application helloworld...
Application helloworld is up.
You can see all services and components using this command:

    swarm status helloworld
```

できた
[http://helloworld-making.gigantic.io/](http://helloworld-making.gigantic.io/)

```
$ curl -v http://helloworld-making.gigantic.io/
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: helloworld-making.gigantic.io
> Accept: */*
>
< HTTP/1.0 200 OK
< Server: SimpleHTTP/0.6 Python/3.4.3
< Date: Thu, 07 May 2015 15:57:33 GMT
< Content-type: text/html
< Content-Length: 28
< Last-Modified: Thu, 07 May 2015 15:54:52 GMT
< Connection: keep-alive
<
Hello from Giant Swarm. \o/
```

`swarm status`で状態を確認できる。

```
swarm status helloworld
App helloworld is up

service             component             image     instanceid    created              status
helloworld-service  helloworld-component  python:3  fvr6utum6ld2  2015-05-07 15:54:12  up
```

### 次はJavaアプリ

```
$ git clone https://github.com/giantswarm/giantswarm-firstapp-java.git
$ cd giantswarm-firstapp-java
```

まずは、ローカルのDockerでアプリを試す。

ちなみに自分はDocker Machineを使う。

```
$ eval $(docker-machine env hoge)
```

```
$ docker-compose build
```

で、このアプリのDockerイメージのビルド。

```
$ docker-compose up
```

で、このアプリとRedisを起動。

```
$ curl -v $(docker-machine ip hoge):4567
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: 192.168.99.100:4567
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=UTF-8
< Content-Length: 76
< Server: Jetty(9.0.z-SNAPSHOT)
< 
Live weather: The current temperature 17 degrees and the wind is 5.076 km/h.
```

２回目以降のアクセスにはRedisでキャッシュされた値を返す。

次にGiant SwarmのDocker Registryにpush

```
$ docker build -t registry.giantswarm.io/$(swarm user)/currentweather .
$ docker push registry.giantswarm.io/$(swarm user)/currentweather
```

Giant Swarmにpush

```
$ swarm up --var=username=$(swarm user)
Creating 'currentweather' in the 'making/dev' environment...
Application created successfully!
Starting application currentweather...
Application currentweather is up.
You can see all services and components using this command:

    swarm status currentweather

$ swarm status currentweather
App currentweather is up

service                 component  image                                         instanceid    created              status
currentweather-service  java       registry.giantswarm.io/making/currentweather  janq4e8pyu2p  2015-05-24 12:15:37  up
currentweather-service  redis      redis                                         fpwksfdwiwrq  2015-05-24 12:15:42  up
```

できた。[http://currentweather-making.gigantic.io/](http://currentweather-making.gigantic.io/)

これを真似て、[こんなアプリ](http://jsug-shop-making.gigantic.io/)もデプロイできた。


----------


ドイツの会社なので、たぶんデータセンターはヨーロッパのあたりだと思う。日本からのアクセスはさすがに遅い。
正式リリース後の値段次第では検討の価値はありそう。もうちょっと遊んでみる。

  [1]: https://giantswarm.io/static/img/logo_simplified_white.svg
