Docker & Golang

So I wrote an article about Swift with Docker and made an issue of using Swift with Docker vs Golang with Docker, I thought I’d write up something about using Golang with Docker to illustrate my point. To start with I don’t need a base Golang image. The compiled application can work with Docker out of the box without adding any libraries, so no need for a base Docker image that contains a runtime.

My Dockerfile for the application

FROM alpine:latest
ADD main /app

Main file

package main

func printSomething() {

func main() {

Jenkins build script

go get -d
go build main.go
docker build -t fritsstegmann/golang .

The result of this process is an image that’s about 6MBs. My Swift application’s Docker image is more than 1.1GB.

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.