fsprojects/docker-fsharp

Name: docker-fsharp

Owner: F# Community Project Incubation Space

Description: This is the official F# docker image repository.

Created: 2015-10-30 14:55:35.0

Updated: 2018-05-04 00:44:23.0

Pushed: 2018-05-04 00:44:22.0

Homepage: https://hub.docker.com/r/_/fsharp/

Size: 34

Language: Shell

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

F# Docker Images

F# is a cross-platform, functional programming language. It features a strong type system, type inference, type providers and a lot of the niceties of OCaml. These Docker images let you get started with F# quickly and build applications based on F#.

The mono image contains the latest mono version with F#, whereas the core image contains the latest .NET Core SDK and runtime.

You can choose between using a SDK image or a Runtime image. The Runtime image is a minimal image with only the dependencies needed to run your already-compiled F# code, while the SDK image also has capabilities for compiling F#.

You can create runtime images by using a continuous integration services to build the software; reference FSharp.Core from your app/service and copy the final output into the Runtime container to create a container that contains just your compiled app.

The up-side of doing it this way is a drastically reduced footprint of your image which translates to lower storage-costs and quicker deploys. When that bug hits the fan, you want to be able to quickly roll back your version or push a fix ? which means you benefit from lower image sizes.

Dependency versions used:

Mono Image
.NET Core Image

CMD

Mono Image

The starting command for the mono image is fsharpi so running the image will result in an F# interactive REPL.

Usage

You can get an FSharp interactive session by simply running the fsharp image:

cker run -it fsharp

nteractive for F# 4.1
ly distributed under the Apache 2.0 Open Source License

help type #help;;

FSharp"; "in"; "Docker"] |> String.concat " " |> printfn "Hello from %s";;
o from FSharp in Docker
it : unit = ()

You can also build and run some F# code in a container. This command will write a short snippet to a Test.fs file, compile it, and then run it.

cker run -it fsharp bash -c "echo 'let [<EntryPoint>] main argv = printfn \"Hello from FSharp in Docker\"; 0' > Test.fs && fsharpc Test.fs && mono Test.exe"

ompiler for F# 4.1
ly distributed under the Apache 2.0 Open Source License
o from FSharp in Docker

With host volume mounts, you can attach a local source directory from your host machine, then do the build in a Docker image. Below is an FSharp source file in the current directory. Map that directory on the host to the /src/ directory on the container with

lume `pwd`:/src

Then run the compiler and finally the application in the container.

After the applications exits, the resulting executable is left.

 
ram.fs 

cker run -it --rm --volume `pwd`:/src fsharp bash -c "cd /src; fsharpc Program.fs && mono Program.exe"

ompiler for F# 4.1
ly distributed under the Apache 2.0 Open Source License

meter of Circle 2.2 = 27.646015
meter of Triangle (3.0,4.6,2.8) = 10.400000
meter of Square 9.1 = 36.400000


ram.exe  Program.fs

To build an image of your own based on the fsharp image, create a Dockerfile such as the following:

 fsharp

Program.fs src/
cd src && fsharpc Program.fs
YPOINT ["mono", "/root/src/Program.exe"] 

This Dockerfile will copy the Program.fs file from the current directory into the image. Then it will change to that directory and compile it. The final step sets the entrypoint, so the resulting Docker image always runs the application.

Build this with docker build -t myapp ..

Then run with docker run --rm myapp and see that the application is run directly. The compilation step was performed when building the image, so this image is ready to execute immediately:

cker run --rm myapp
meter of Circle 2.2 = 27.646015
meter of Triangle (3.0,4.6,2.8) = 10.400000
meter of Square 9.1 = 36.400000
Core Image

The entry point for the core image in /bin/bash as there is no interactive F# REPL available for .NET Core at this time.

Without a REPL, the primary use cases for the core image are building .NET Core applications or using it as a base for another image.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.