A Haskell Docker Local Development Environment Guide

In this post we’re going to walk through setting up a local Haskell Docker development environment for Haskell projects. We’re going to build it from scratch so you can see how it all works.

First, We’re going to assume you have Docker properly installed.

Haskell command line programs.

First up is your simple command line programs. The goal here is to be able to run Haskell programs from GHCI in a prelude session in a Docker container.

The first step is to create a project directory and our Dockerfile. We’ll be using the Haskell image. Here’s the code for that:

$ mkdir haskellProject
$ cd haskellProject

Your Dockerfile named “Dockerfile” is a measly 2 lines:

FROM haskell:8

The FROM haskell:8 section grabs the pre-existing haskell image, and the WORKDIR /test puts us into the /test directory, which is where we’ll put our haskell files so we can run them.

Next we need to build that image so we can run a container off it. From the directory that your Dockerfile is located, run the command below:

$ docker build -t haskell/test .

That creates an image called haskell/test. You can change the name. Now that we have an image on our system we just need to start a container based off our new haskell/test image. Run this command from that same directory to start a container:

docker container run -it -v $(pwd):/test haskell/test

The above command works as follows: docker container run is the command to start a container. -i keeps STDIN open and -t is a Pseudo TTY. I’m too lazy to figure out what that means but it helps us have that interactive prelude session and lets us escape out of it with :q.

The -v $(pwd):/test is a “bind mount” that connects our “present working directory” (code on our local machine) to the /test directory inside the container. This allows us to make changes to code in our local computer and have it take effect inside the Docker container.

With that command you should be spit into a prelude and can hopefully take it from here.

Docker + Haskell + Yesod??

Unfortunately I haven’t figured out yet how to get Haskell Web apps working with Docker. The container conflicts with Stack for some reason, BUT there is some built in Docker integration you can try to read through here: https://docs.haskellstack.org/en/stable/docker_integration/#configuration. I’ll finish this post when I figure it out.

Leave a Comment

Your email address will not be published. Required fields are marked *

want more details?

Fill in your details and we'll be in touch