Skip to content

Instantly share code, notes, and snippets.

@abranhe
Last active May 14, 2020 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abranhe/9ddd31edd4549669fb975e2d734fdd1b to your computer and use it in GitHub Desktop.
Save abranhe/9ddd31edd4549669fb975e2d734fdd1b to your computer and use it in GitHub Desktop.
Running Swift on Docker

Running Swift on Docker

You must install Docker first. It is avilable for Windows, Mac and Linux

Setup

Create the image where your Dockerfile and fibonacci.swift are located.

docker build -t swift .

Usage

Run the swift container and then run your program inside the container

docker run -it swift /bin/bash

or just

docker run -it swift

after you are inside the Docker container you will get a prompt like this:

root@885b0d4180cc:/#

just run

swift fibonacci.swift

the result will be

Fibonacci of 30: 832040
FROM swiftdocker/swift:latest
ADD fibonacci.swift
//
// fibonacci.swift
//
// Author: Abraham Hernandez (https://github.com/abranhe)
//
func fibonacci(i: Int) -> Int {
if i <= 2 {
return 1
} else {
return fibonacci(i: i - 1) + fibonacci(i: i - 2)
}
}
print("Fibonacci of 30: " + String(fibonacci(i: 30)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment