Essay - Published: 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.
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).
So yes a bit of extra work but I think it pays dividends long term.
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.
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.
Dockerfile
Building the app
Run the app
# 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
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
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:
The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.