Create Ubuntu 14.04 docker image with the latest Swift preview snapshot

Short tutorial if you need a quick way to test Swift code on Linux.

First, you need to download the latest available Swift preview from:

https://swift.org/download/

(currently it's https://swift.org/builds/swift-3.0-preview-6/ubuntu1404/swift-3.0-PREVIEW-6/swift-3.0-PREVIEW-6-ubuntu14.04.tar.gz)

Download Docker for Mac from https://www.docker.com/products/docker#/mac

Install and run Docker.

Open two terminal windows.

The first terminal window will be used to enter docker commands (i.e. to start/save the container), the commands are prefixed with:

macbook:~ sdrpa$ ...

The second terminal will be the container running Ubuntu, the commands are prefixed with:

root@a3f8e5c13ff8:/# ...

Here we go:

Pull ubuntu 14.04 image and run a container:

macbook:~ sdrpa$ docker pull ubuntu:14.04
macbook:~ sdrpa$ docker run --privileged -t -i ubuntu:14.04 /bin/bash

Get the container's name:

macbook:~ sdrpa$ docker ps

Copy Swift archive to the container:

macbook:~ sdrpa$ docker cp /Users/sdrpa/swift-3.0-PREVIEW-6-ubuntu14.04.tar.gz <CONTAINER NAME>:/root/swift-3.0-PREVIEW-6-ubuntu14.04.tar.gz

Now inside the container extract and delete the archive:

root@a3f8e5c13ff8:/# tar -xvf swift-3.0-PREVIEW-6-ubuntu14.04.tar.gz
root@a3f8e5c13ff8:/# rm -f swift-3.0-PREVIEW-6-ubuntu14.04.tar.gz

Install required libs:

root@a3f8e5c13ff8:/# apt-get update
root@a3f8e5c13ff8:/# apt-get install clang
root@a3f8e5c13ff8:/# apt-get install binutils
root@a3f8e5c13ff8:/# apt-get install libedit2
root@a3f8e5c13ff8:/# apt-get install libicu52
root@a3f8e5c13ff8:/# apt-get install libxml2
root@a3f8e5c13ff8:/# apt-get install python2.7-dev

Edit PATH so Ubuntu can find Swift binaries (I prefer nano but you can use vi):

root@a3f8e5c13ff8:/# apt-get install nano
root@a3f8e5c13ff8:/# cd ~
root@a3f8e5c13ff8:/# nano .profile and add export PATH=/root/swift-3.0-PREVIEW-6-ubuntu14.04/usr/bin:"${PATH}"
root@a3f8e5c13ff8:/# source .profile

The container is ready, save the changes:

macbook:~ sdrpa$ docker ps -l
macbook:~ sdrpa$ docker commit <CONTAINER ID> swift

To start container next time:

macbook:~ sdrpa$ docker run --privileged -t -i swift /bin/bash --login

Related links:

http://www.swiftprogrammer.info/swiftubuntu1.html

http://code.tutsplus.com/tutorials/how-to-use-swift-on-linux--cms-25934