How to run an F# + Falco Webapp in a Docker Container

Date: 2025-03-28 | containers | craft | create | docker | docker-compose | falco | fsharp | webapp |

DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)

Previously we walked through building a basic webapp with F# and Falco:

In this post we'll be adding a Docker container to make it easier to build once and run anywhere.

HAMINIONs Members get full access to the project files (GitHub) along with dozens of other example projects we talk about on the blog.

Why Run Apps in a Docker Container?

I build most of my apps in Docker containers. I like containers because they allow a relatively simple way to declare your app's dependencies in code. It adds a bit of complexity to unlock something approximating build once and run anywhere (that can run containers).

  • Infrastructure as code to get ~deterministic builds
  • Can run ~anywhere Docker is installed making it easy to share and run code on other machines (whether for example projects or deploying to remote servers)
  • Easier to spin up multiple services together - like an app and related development database

So yes a bit of extra work but I think it pays dividends long term.

How to run an app in a Docker Container

First you need Docker installed on your machine. There are several official guides for most major operating systems - Mac, Windows, popular Linux flavors.

That will allow the machine to run a Docker container and then we just need to specify how the container is built and how to run it.

  • Dockerfile - How to build and start the specified container.
  • Docker Compose - Allows additional configuration for multiple containers like what volumes to use and ports to attach to.

Note: Docker Compose is not strictly necessary for this example but I find it to be very helpful to specify additional run-time information as code and basically required if spinning up dependent containers (as I do with CloudSeed my F# project template) so including it here.

Code walkthrough

Dockerfile

Building the app

  • Start with a base Ubuntu image with dotnet installed - pulled from their official repo
  • Copy my fsproj into it
  • Run dotnet restore to install dependencies
  • Copy the rest of the in here
  • Build the app

Run the app

  • Create a new layer for running the app
  • Copy in build artifacts
  • Run it
# Build Dotnet App

FROM mcr.microsoft.com/dotnet/sdk:9.0-bookworm-slim AS build
EXPOSE 80

WORKDIR /source

## copy csproj and restore as distinct layers
COPY ./*.fsproj ./
RUN dotnet restore

## copy and publish app and libraries
COPY . .
RUN dotnet publish -c release -o /app

# Copy build / styles into final location

FROM mcr.microsoft.com/dotnet/aspnet:9.0
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "web.dll"]

Docker Compose

  • Declare the service
  • Declare build directory - useful if you have a /source or something
  • Give it a container name - uniquely identifies the service on your machine
  • Specify how the machine port should map to the container port - it runs on 5001 on my machine
  • Give environment variables
  • Add a volume (Not used here but could be useful in future)
services:
  cloudseed_app_env:
    build: ./
    container_name: 2025-03_fsharp-falco-with-docker
    ports:
      - 5001:8080
    environment:
      # Environment Variables set in App/appsettings.*.json
      ASPNETCORE_ENVIRONMENT: Development
    volumes:
      - ~/.vsdbg:/remote_debugger:rw

Next

So that's how you can run an F# + Falco webapp in Docker.

As a reminder HAMINIONs Members get full access to the project files (GitHub) if you just want to git clone and run it yourself.

If you want to see how I build, run, and deploy my F# + Falco webapps to production check out CloudSeed my F# project template.

If you liked this post you might also like:

Want more like this?

The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.