Over a million developers have joined DZone.

How to Deploy and Run Swift Kitura Applications With Docker

DZone's Guide to

How to Deploy and Run Swift Kitura Applications With Docker

Since being open sourced, Swift has found a second life running on servers everywhere. In this article you will see how easy it is to deploy Kitura apps with Docker.

· Mobile Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

At InterConnect IBM announced and demonstrated various ways to run Swift code on the server. You can use the Swift runtime in Bluemix (Cloud Foundry buildpack), you can use the Swift Sandbox, you can write event based logic with OpenWhisk and you can run Swift in Docker containers on Bluemix. With these capabilities, iOS developers can now write server-side code in the same language used for mobile apps.

In order to build REST APIs with Swift, you need a web framework. For Node.js applications typically the Express framework is used. The counterpart for Swift is Kitura. Here is how my colleague Robert Dickerson describes Kitura.

Kitura is a lightweight web framework that allows you to easily build web services with complex routes. Much of its design was inspired by Express.js based on the success of its overall design in particular URL routing and pluggable middleware. Kitura takes these principles and adds the advantages of Swift.


Robert wrote a great tutorial how to use Kitura and run it locally. I tried to package up his ToDo sample in a Docker image and run it as a container so that you can deploy the application to Bluemix. Turns out that at this point you need to do one extra step before you can run the ibmcom/swift-ubuntu image as Robert told me.

Download pcre and unpack it into a sub-folder ‘pcre2-10.20’ of your project. After this add this Dockerfile to the root.

FROM ibmcom/swift-ubuntu:latest
USER root
RUN apt-get install -y libhttp-parser-dev libcurl4-openssl-dev libhiredis-dev 
COPY ./pcre2-10.20 /root/
RUN cd /root && ./configure && make && make install
RUN cd /root && mkdir swift-helloworld
COPY . /root/swift-helloworld/
RUN cd /root/swift-helloworld && swift build -Xcc -fblocks -Xswiftc -I/usr/local/include -Xlinker -L/usr/local/lib
CMD ["/root/swift-helloworld/.build/debug/TodoList"]

To build the image and run the container invoke these commands.

docker build -t swift-todos . 
docker run --name swift-todos -p 8090:8090 -d -t swift-todos

After this, the REST APIs can be invoked via ‘http://dockerhost:8090’. To deploy it to Bluemix follow the documentation.


Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

bluemix ,swift ,kitura

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}