Swift を Docker 上の Linux(Ubuntu) で動作させる

資料

手順

Docker 側

1. Docker をインストール
$ brew cask install docker
2. Ubuntu のイメージを得る
$ docker pull ubuntu
3. Ubuntu コンテナを作成
$ docker run --privileged -it ubuntu /bin/bash
4. コンテナ開始
$ docker start <ID>
5. コンテナにアタッチ
$ docker attach <ID>

Ubuntu

1. パッケージを更新
# apt update
2. Swift に必要なパッケージを得る
# apt-get install git cmake ninja-build clang python uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev systemtap-sdt-dev tzdata rsync
3. Swift をダウンロード
# cd /opt/
# apt-get install wget
# wget https://swift.org/builds/swift-5.0-release/ubuntu1604/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu16.04.tar.gz
4. Unzip
# tar xvfz swift-5.0-RELEASE-ubuntu16.04.tar.gz
# mv swift-5.0-RELEASE-ubuntu16.04 swift
5. パス設定
# export PATH=/opt/swift/usr/bin:"${PATH}"
6. テスト
# swift -version
Swift version 5.0 (swift-5.0-RELEASE)
Target: x86_64-unknown-linux-gnu

メモ

ホストのファイルをコンテナにコピー

$ docker cp file.cnf <ID>:/etc/file.cnf
$ docker cp dir <ID>:/etc/dir