LoginSignup
14
10

More than 5 years have passed since last update.

KituraをDockerで動かしてみた。

Posted at

Dockerコンテナ上でkituraのサーバーを動かす

今回はこちらのIBMさん謹製のDockerfileを使用します。
https://github.com/IBM-Swift/kitura-ubuntu-docker
このレポジトリをクローン。
(実際に必要なのはDockerfileと.shファイル)

git clone https://github.com/IBM-Swift/kitura-ubuntu-docker.git

レポジトリに移動し、Dockerイメージを作成します。

docker build .

次にDockerを起動。/bin/bashでコンテナ上のbashを開きます。
ついでにホストとコンテナの8090ポートを繋いでおきます。

docker run -p 8090:8090 -it ibmcom/kitura-ubuntu /bin/bash

あとは次のエントリに従いコンテナ上でファイルを作成。
KituraでHello Worldを表示させる

起動(コンテナ上)。

.build/debug/myFirstProject

これでDockerコンテナのサーバーにlocalhost:8090でアクセスできます。

ファイルの共有

作成するアプリケーションのファイルはgit等で管理したいので、
次にファイルをホストマシンと共有してみます。
先ほど使用したコンテナを一度破棄し、

docker rm コンテナのID

ホストにディレクトリを作成しておきます。

mkdir myFirstProject

そして次は以下のコマンドでコンテナを作成&起動。

docker run -p 8090:8090 -v $(pwd)/myFirstProject:/myFirstProject -it ibmcom/swift-ubuntu /bin/bash

-vオプションによりホストのmyFirstProjectディレクトリとコンテナ上のmyFirstProjectディレクトリを共有します。

コンテナ上でmyFirstProjectディレクトリに移動し、あとは先ほどと同様、

swift package init --executable

とすると、ホストマシンのmyFirstProjectディレクトリが以下のようになっていると思います。

myFirstProject
├── Package.swift
├── Sources
│ └── main.swift
└── Tests

あとは好きなエディタ(Xcode)でコードを書いて...
コンテナ上でビルド&Run

swift build
.build/debug/myFirstProject

スクリーンショット 2016-11-18 11.19.14.png

めでたしめでたし。

おわりに

macでも快適にDockerが使えるようになり、またKituraも1.0を迎えたことで、
いよいよもってサーバーサイドSwiftへの期待が高まりますね。

参考

IBM-Swift/kitura-ubuntu-docker
KituraでHello Worldを表示させる
Getting Started

14
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
10