Docker & Swift Lang

Swift is a relatively new language from Apple that replaces Objective C for IOS and MacOS development. Apple open sourced the language a while ago and it now has official support on Ubuntu(using it on other Linux distributions is a bit troublesome). The issue using it on other Linux systems is the dynamic linking of libraries, I’ve tried using Swift’s ability to statically link libraries, it succeeded in including the swift runtime libraries but it failed to include other lower level runtime libraries. I had to create another docker base image that includes the swift tools for compiling the application based on Ubuntu 16.04. To run the Swift application in docker we have to compile the application in the container it will run in.

My Dockerfile for the base Swift image

FROM ubuntu:16.04

RUN apt-get update && apt-get install -y wget clang libstdc++6 libicu-dev libbsd-dev libxml2 libcurl3 \
        && cd /root \
        && wget \
        && tar xfzv swift-3.0.1-RELEASE-ubuntu16.04.tar.gz \
        && cd /usr/local/bin \
        && ln -s /root/swift-3.0.1-RELEASE-ubuntu16.04/usr/bin/swift \
        && ln -s /root/swift-3.0.1-RELEASE-ubuntu16.04/usr/bin/swiftc

My Dockerfile for the Swift application

FROM fritsstegmann/swift

RUN mkdir /app
ADD . /app/

RUN swift build --configuration release

ENTRYPOINT [".build/release/app"]

Package file

import PackageDescription

let package = Package(
    name: “app”,
    targets: []

Main file

func sayHello() {
  print("Hello, World!")


My gripe with Swift is that the linking issue makes distributing an application over different Linux distributions difficult. It makes Swift a less attractive option over Golang in a container crazed world. I’d prefer to have compiled the application with Jenkins and then copy only the binaries to the application container.