Docker で PlayFramework2 の環境を作るメモ書き


DockerでPlayFrameworkが動くと聞いて試して見たメモ


## Dockerfile

https://registry.hub.docker.com/u/adamalex/play-docker-ci/

これを利用

最終的には Typesafe Activator が動くっぽい。

```shell
[yasui@Yasui-MBA2: ~/Documents/develop/docker-play][15:35-09/09/14] $ boot2docker init
2014/09/09 15:35:42 Creating VM boot2docker-vm...
2014/09/09 15:35:42 Apply interim patch to VM boot2docker-vm (https://www.virtualbox.org/ticket/12748)
2014/09/09 15:35:42 Setting NIC #1 to use NAT network...
2014/09/09 15:35:43 Port forwarding [ssh] tcp://127.0.0.1:2022 --> :22
2014/09/09 15:35:43 Port forwarding [docker] tcp://127.0.0.1:2375 --> :2375
2014/09/09 15:35:43 Setting NIC #2 to use host-only network "vboxnet1"...
2014/09/09 15:35:43 Setting VM storage...
2014/09/09 15:35:52 Done. Type `boot2docker up` to start the VM.

[yasui@Yasui-MBA2: ~/Documents/develop/docker-play][15:35-09/09/14] $ boot2docker up
2014/09/09 15:35:58 Waiting for VM to be started...
............
2014/09/09 15:36:34 Started.
2014/09/09 15:36:34 To connect the Docker client to the Docker daemon, please set:
2014/09/09 15:36:34     export DOCKER_HOST=tcp://192.168.59.103:2375

[yasui@Yasui-MBA2: ~/Documents/develop/docker-play][15:36-09/09/14] $ export DOCKER_HOST=tcp://192.168.59.103:2375

[yasui@Yasui-MBA2: ~/Documents/develop/docker-play][15:37-09/09/14] $ docker build --tag='myplayapp' .
Sending build context to Docker daemon 4.096 kB
Sending build context to Docker daemon
Step 0 : FROM        ubuntu:14.04
Pulling repository ubuntu
826544226fdc: Download complete
511136ea3c5a: Download complete
b3553b91f79f: Download complete
ca63a3899a99: Download complete
ff01d67c9471: Download complete
7428bd008763: Download complete
c7c7108e0ad8: Download complete
...<中略>
 ---> 024e10e08e02
Removing intermediate container ad2584cc710d
Step 7 : ADD         app /root/app
2014/09/09 15:44:28 app: no such file or directory

[yasui@Yasui-MBA2: ~/Documents/develop/docker-play][15:44-09/09/14] $
```


Play のプロジェクト内で `docker build` をする気配だったので、ちょっとやり直し。

```shell
[yasui@Yasui-MBA2: ~/Documents/develop/docker-play][15:45-09/09/14] $ ls
./		../		Dockerfile
[yasui@Yasui-MBA2: ~/Documents/develop/docker-play][15:45-09/09/14] $ play new fakeit
       _
 _ __ | | __ _ _  _
| '_ \| |/ _' | || |
|  __/|_|\____|\__ /
|_|            |__/

play 2.2.3 built with Scala 2.10.3 (running Java 1.6.0_65), http://www.playframework.com

The new application will be created in /Users/yasui/Documents/develop/docker-play/fakeit

What is the application name? [fakeit]
>

Which template do you want to use for this new application?

  1             - Create a simple Scala application
  2             - Create a simple Java application

> 1
OK, application fakeit is created.

Have fun!

[yasui@Yasui-MBA2: ~/Documents/develop/docker-play][15:46-09/09/14] $ mv Dockerfile fakeit
[yasui@Yasui-MBA2: ~/Documents/develop/docker-play][15:46-09/09/14] $ cd fakeit
[yasui@Yasui-MBA2: ~/Documents/develop/docker-play/fakeit][15:46-09/09/14] $ ls
./		../		.gitignore	Dockerfile	README		app/		build.sbt	conf/		project/	public/		test/
[yasui@Yasui-MBA2: ~/Documents/develop/docker-play/fakeit][15:46-09/09/14] $ docker build --tag='myplayapp' .
<中略>
Removing intermediate container 5b91b72a03f8
Step 18 : EXPOSE      9000
 ---> Running in ce520b393fe9
 ---> 3c85624c2101
Removing intermediate container ce520b393fe9
Successfully built 3c85624c2101
[yasui@Yasui-MBA2: ~/Documents/develop/docker-play/fakeit][15:54-09/09/14] $

```


ビルドできたので、起動させる

```shell
[yasui@Yasui-MBA2: ~/Documents/develop/docker-play/fakeit][16:04-09/09/14] $ docker run -i -t -p 9000:9000 myplayapp
Play server process ID is 9
[info] play - Application started (Prod)
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
```

まぁ、こんな感じ。

ファイル更新するたびにdockerを再起動する必要があるとか、まだここら辺の対処がわかんないけど、こんな感じで動く。