Dockerfiles

Collection of Dockerfiles to create Swift 3 environments on Ubuntu 16.04 for developers

Dockerfiles for Swift

Docker Version Ubuntu Swift Version Vapor Toolbox Vapor Plaform License MIT

Collection of Dockerfiles to create Swift 3 environments on Ubuntu 16.04 for developers

Table of contents

Docker

What is Docker?

Docker is an open-source project that automates the deployment of Linux applications inside software containers

What is a Dockerfile?

Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.

Install Docker on Mac

Since June 20th, 2016, Docker for Mac is available.

image

(just click on the image and follow the instructions)

Docker Images

Install environment

You just have to clone this repository:

$ git clone https://github.com/TofPlay/Dockerfiles

All images are built in the Dockerfiles folder

Basic Images

clang image

  • Image base on: ubuntu:16.04
  • Instruction to build: docker build -t clang clang/
  • Description: Create an image with the clang environment

swift3 image

  • Image base on: ubuntu:16.04 ► clang
  • Instruction to build: docker build -t swift3 swift3/
  • Description: Install the Swift 3.0.2 environment on Linux. Can be used to build all Swift 3 applications on Linux.
$ docker run -ti --rm \
                 --name swift3 \
                 swift3

[email protected]:/# swift --version
Swift version 3.0.2 (swift-3.0.2-RELEASE)
Target: x86_64-unknown-linux-gnu

Vapor Images

Vapor is web framework for Swift work on macOS and Ubuntu

If you have your vapor sources projects are on/Volumes/Sources/vapor/projects you must declare this folder in the File Sharing like this:

image

vapor image

  • Image base on: ubuntu:16.04 ► clang ► swift3
  • Instruction to build: docker build -t vapor vapor/
  • Description: Download and compiled vapor on Linux. Can be used by a developer to develop web site or/and REST Api.

On your Mac open Terminal and enter the following command. You will launch the container and map /Volumes/Sources/vapor/projects to /vapor on the container:

$ pwd
/Volumes/Sources/
$ docker run -ti --rm \
                 --name vapor \
                 -p 127.0.0.1:8080:8080 \
                 -v $(pwd)/vapor/projects:/vapor \
                 vapor

On the container to build your project (replace ItWorks by your project):

[email protected]:/vapor# cd ItWorks/
[email protected]:/vapor/ItWorks# # If you update `package.swift` you must execute
[email protected]:/vapor/ItWorks# vapor build --clean
[email protected]:/vapor/ItWorks# # Otherwise just execute
[email protected]:/vapor/ItWorks# vapor build 
Fetching Dependencies [Done]
Building Project [Done]

To run your project on the container:

[email protected]:/vapor/ItWorks# vapor run serve
Running ItWorks...
No preparations.
Server 'default' starting at 0.0.0.0:8080

To test your project on your Mac open the browser and enter the url: http://localhost:8080/ image

vapor-mysql image

  • Image base on: ubuntu:16.04 ► clang ► swift3 ► vapor
  • Instruction to build: docker build -t vapor-mysql vapor-mysql/
  • Description: Install mysql on the container, pre-create vapor database and vapor user (without password)

On your Mac open Terminal and enter the following command. You will launch the container and map /Volumes/Sources/vapor-mysql/projects to /vapor on the container:

$ pwd
/Volumes/Sources/
$ docker run -ti --rm \
                 --name vapor-mysql \
                 -p 127.0.0.1:8080:8080 \
                 -p 127.0.0.1:3306:3306 \
                 -v mysql.data:/var/lib/mysql \
                 -v $(pwd)/vapor-mysql/projects:/vapor \
                 vapor-mysql
                 
 * Starting MySQL database server mysqld                                 [ OK ]
[email protected]:/vapor#

On the container to build your project (replace ItWorks-MySQL by your project):

[email protected]:/vapor# cd ItWorks-MySQL/
[email protected]:/vapor/ItWorks-MySQL# # If you update `package.swift` you must execute
[email protected]:/vapor/ItWorks-MySQL# vapor build --clean
[email protected]:/vapor/ItWorks-MySQL# # Otherwise just execute
[email protected]:/vapor/ItWorks-MySQL# vapor build
No Packages folder, fetch may take a while...
Fetching Dependencies [Done]
Building Project [Done]
[email protected]:/vapor/ItWorks-MySQL#

To run your project on the container:

[email protected]:/vapor/ItWorks-MySQL# vapor run serve
Running ItWorks-MySQL...
No preparations.
Server 'default' starting at 0.0.0.0:8080
GET /version

To test your project on your Mac open the browser and enter the url: http://localhost:8080/version image

If you run the following command you should see:

$ docker volume ls
DRIVER              VOLUME NAME
local               mysql.data

mysql.data is a data volume. All changes on /var/lib/mysql on the container will be persistent.

vapor-postgresql image

  • Image base on: ubuntu:16.04 ► clang ► swift3 ► vapor
  • Instruction to build: docker build -t vapor-postgresql vapor-postgresql/
  • Description: Install PostgreSQL on the container, pre-create vapor database and vapor user (without password)

On your Mac open Terminal and enter the following command. You will launch the container and map /Volumes/Sources/vapor-mysql/projects to /vapor on the container:

$ pwd
/Volumes/Sources/
$ docker run -ti --rm \
                 --name vapor-postgresql \
                 -p 127.0.0.1:8080:8080 \
                 -p 127.0.0.1:5432:5432 \
                 -v postgresql.data:/var/lib/postgresql/9.5/main \
                 -v $(pwd)/vapor-postgresql/projects:/vapor \
                 vapor-postgresql
                 
 * Starting PostgreSQL 9.5 database server                               [ OK ]
[email protected]:/vapor#

On the container to build your project (replace ItWorks-PostgreSQL by your project):

[email protected]:/vapor# cd ItWorks-PostgreSQL/
[email protected]:/vapor/ItWorks-PostgreSQL# # If you update `package.swift` you must execute
[email protected]:/vapor/ItWorks-PostgreSQL# vapor build --clean
[email protected]:/vapor/ItWorks-PostgreSQL# # Otherwise just execute
[email protected]:/vapor/ItWorks-PostgreSQL# vapor build
No Packages folder, fetch may take a while...
Fetching Dependencies [Done]
Building Project [Done]
[email protected]:/vapor/ItWorks-PostgreSQL#

To run your project on the container:

[email protected]:/vapor/ItWorks-PostgreSQL# vapor run serve
Running ItWorks-PostgreSQL...
No preparations.
Server 'default' starting at 0.0.0.0:8080
GET /version

To test your project on your Mac open the browser and enter the url: http://localhost:8080/version image

If you run the following command you should see:

$ docker volume ls
DRIVER              VOLUME NAME
local               progresql.data

progresql.data is a data volume. All changes on /var/lib/postgresql/9.5/main on the container will be persistent.

vapor-sqlite image

  • Image base on: ubuntu:16.04 ► clang ► swift3 ► vapor
  • Instruction to build: docker build -t vapor-sqlite vapor-sqlite/
  • Description: Install PostgreSQL on the container, pre-create vapor database and vapor user (without password)

On your Mac open Terminal and enter the following command. You will launch the container and map /Volumes/Sources/vapor-sqlite/projects to /vapor on the container:

$ pwd
/Volumes/Sources/
$ docker run -ti --rm \
                 --name vapor-sqlite \
                 -p 127.0.0.1:8080:8080 \
                 -v $(pwd)/vapor-sqlite/projects:/vapor \
                 vapor-sqlite
[email protected]:/vapor#

On the container to build your project (replace ItWorks-Sqlite by your project):

[email protected]:/vapor# cd ItWorks-Sqlite/
[email protected]:/vapor/ItWorks-Sqlite# # If you update `package.swift` you must execute
[email protected]:/vapor/ItWorks-Sqlite# vapor build --clean
[email protected]:/vapor/ItWorks-Sqlite# # Otherwise just execute
[email protected]:/vapor/ItWorks-Sqlite# vapor build
No Packages folder, fetch may take a while...
Fetching Dependencies [Done]
Building Project [Done]
[email protected]:/vapor/ItWorks-Sqlite#

To run your project on the container:

[email protected]:/vapor/ItWorks-Sqlite# vapor run serve
Running ItWorks-Sqlite...
No preparations.
Server 'default' starting at 0.0.0.0:8080
GET /version

To test your project on your Mac open the browser and enter the url: http://localhost:8080/version image

To build all images

Execute command

$ ./build --image=all 

This script will build clang, swift3 and all vapor images

Images on the cloud

All images are avalaible on Docker Store:

image

Run clang image from the cloud

$ docker run -ti --rm \
                 --name clang \
                 tofdocker/clang:1.2

Run swift3 image from the cloud

$ docker run -ti --rm \
                 --name swift3 \
                 tofdocker/swift3:1.2

Run vapor image from the cloud

$ pwd
/Volumes/Sources/
$ docker run -ti --rm \
                 --name vapor \
                 -p 127.0.0.1:8080:8080 \
                 -v $(pwd)/vapor/projects:/vapor \
                 tofdocker/vapor:1.4

Run vapor-mysql image from the cloud

$ pwd
/Volumes/Sources/
$ docker run -ti --rm \
                 --name vapor-mysql \
                 -p 127.0.0.1:8080:8080 \
                 -p 127.0.0.1:3306:3306 \
                 -v mysql.data:/var/lib/mysql \
                 -v $(pwd)/vapor-mysql/projects:/vapor \
                 tofdocker/vapor-mysql:1.4

Run vapor-postgresql image from the cloud

$ pwd
/Volumes/Sources/
$ docker run -ti --rm \
                 --name vapor-postgresql \
                 -p 127.0.0.1:8080:8080 \
                 -p 127.0.0.1:5432:5432 \
                 -v postgresql.data:/var/lib/postgresql/9.5/main \
                 -v $(pwd)/vapor-postgresql/projects:/vapor \
                 tofdocker/vapor-postgresql:1.4

Run vapor-sqlite image from the cloud

$ pwd
/Volumes/Sources/
$ docker run -ti --rm \
                 --name vapor-sqlite \
                 -p 127.0.0.1:8080:8080 \
                 -v $(pwd)/vapor-sqlite/projects:/vapor \
                 tofdocker/vapor-sqlite:1.4

Resources

If you are interested with Swift backend I invite you to visit my collection on Google+: Swift Backend. You will find articles and tutorials on Vapor for example

Related Repositories

dockerfiles

dockerfiles

Various Dockerfiles I use on the desktop and on servers. ...

dockerfiles

dockerfiles

Various Dockerfiles I use on the desktop and on servers. ...

CentOS-Dockerfiles

CentOS-Dockerfiles

Dockerfiles for various common implementations ...

Fedora-Dockerfiles

Fedora-Dockerfiles

Fedora Dockerfiles ...

dockerfiles

dockerfiles

dockerfiles ...