A step-by-step guide to set up an OCaml development environment using Docker and VS Code Dev Containers.
Make sure you have the following before you begin.
Select your operating system to see the matching instructions.
Download Docker Desktop
Visit docker.com/products/docker-desktop and download the installer for macOS.
Install and launch Docker Desktop
Open the downloaded .dmg file, drag Docker to Applications, and launch it. Allow any system permissions when prompted.
Verify Docker is running
Open Terminal and run:
docker --version
You should see a version number like Docker version 27.x.x.
Enable WSL 2 (if not already enabled)
Open PowerShell as Administrator and run:
wsl --install
Restart your computer if prompted.
Download Docker Desktop
Visit docker.com/products/docker-desktop and download the installer for Windows.
Install and launch Docker Desktop
Run the installer, ensure "Use WSL 2 instead of Hyper-V" is checked, and follow the prompts. Launch Docker Desktop after installation.
Verify Docker is running
Open PowerShell and run:
docker --version
You should see a version number like Docker version 27.x.x.
This extension lets VS Code develop directly inside a Docker container.
Open Visual Studio Code.
Open the Extensions view
Press Ctrl+Shift+X on Windows/Linux, or Cmd+Shift+X on macOS.
Search for Dev Containers (by Microsoft) and click Install.
The assignment repository includes a pre-configured Dev Container. Just clone and open.
Clone the repository
Open a terminal and run:
git clone https://github.com/dgistpl/CSE307-2026spring.git
Open the folder in VS Code
code CSE307-2026spring
Reopen in Container
VS Code will detect the .devcontainer/devcontainer.json file and show a notification:
Click “Reopen in Container”.
Alternatively, open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) and select:
Dev Containers: Reopen in Container
Wait for the container to build
The first build may take several minutes as Docker downloads the OCaml image and installs tools. Subsequent launches will be fast.
Run these commands in the VS Code terminal (inside the container) to make sure everything works.
ocaml --version
Expected output: The OCaml toplevel, version 5.2.x
Launch utop for an interactive OCaml session:
utop
Try typing an expression:
List.map (fun x -> x * x) [1; 2; 3; 4; 5];;
Expected output: - : int list = [1; 4; 9; 16; 25]
utop.
You can run OCaml files directly or load them in utop:
# Run an OCaml file directly
ocaml hw1/problem1.ml
# Or load it in utop
utop
# Then type: #use "hw1/problem1.ml";;
Useful commands for OCaml development.
| Command | What it does |
|---|---|
ocaml file.ml |
Run an OCaml file directly |
utop |
Start the enhanced interactive REPL with auto-completion |
#use "file.ml";; |
Load a file inside utop |
dune build |
Build the project using Dune |
dune exec ./main.exe |
Build and run an executable |
dune test |
Run tests defined in the project |
opam list |
List installed OCaml packages |
opam install <package> |
Install a new OCaml package |
Common issues and how to fix them.
| Problem | Solution |
|---|---|
| Docker not running | Make sure Docker Desktop is running before opening VS Code. |
| Container build fails | Open the Command Palette and select Dev Containers: Rebuild Container. |
| Permission issues on Linux | Add your user to the docker group: sudo usermod -aG docker $USER, then log out and back in. |
| opam environment not set | Run eval $(opam env) in the terminal. |