Giter Site home page Giter Site logo

natsukagami / docker-fsharp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fsprojects-archive/zzarchive-docker-fsharp

0.0 3.0 0.0 43 KB

This is the official F# docker image repository.

Home Page: https://hub.docker.com/r/_/fsharp/

License: MIT License

Dockerfile 84.88% Shell 15.12%

docker-fsharp's Introduction

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

  • Mono 5.14.0.177

.NET Core Image

  • .NET Core 2.1.401 SDK

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:

# docker run -it fsharp

F# Interactive for F# 4.1
Freely distributed under the Apache 2.0 Open Source License

For help type #help;;

> ["FSharp"; "in"; "Docker"] |> String.concat " " |> printfn "Hello from %s";;
Hello from FSharp in Docker
val 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.

# docker 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"

F# Compiler for F# 4.1
Freely distributed under the Apache 2.0 Open Source License
Hello 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

--volume `pwd`:/src

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

After the applications exits, the resulting executable is left.

# ls 
Program.fs 

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

F# Compiler for F# 4.1
Freely distributed under the Apache 2.0 Open Source License

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

# ls
Program.exe  Program.fs

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

FROM fsharp

ADD Program.fs src/
RUN cd src && fsharpc Program.fs
ENTRYPOINT ["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:

# docker run --rm myapp
Perimeter of Circle 2.2 = 27.646015
Perimeter of Triangle (3.0,4.6,2.8) = 10.400000
Perimeter 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.

docker-fsharp's People

Contributors

haf avatar juicelink avatar mastoj avatar natsukagami avatar nickbabcock avatar ninjarobot avatar sebfia avatar tianon avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.