Docker and OCaml
TL;DR for OPAM use
- Base image for Debian available via
ocaml/opam. Use it in a Dockerfile via
FROM ocaml/opamor directly via
docker run -it ocaml/opamto get an interactive shell with OPAM initialised.
- The images all contain an
opamuser with the default remote as
/home/opam/opam-repository. You can merge extra commits in there and run
opam update(e.g. to test PRs).
- See this travis.yml for an example of how to do multi-distro testing.
- Look at opam install docker-infra for CLI commands that generate Dockerfiles for your projects.
Building a development image
- The ocaml-dockerfile repository has a DSL to generate your own Dockerfiles programmatically.
- The ocaml-docker-infra repository has CLI commands that generate Dockerfiles for your projects for common tasks such as building PRs from GitHub.
TODO Use build hooks for efficient Alpine images, see avsm/experiment-dchooks
There are several sets of layered images published on the Docker Hub:
- ocaml/ocaml: The base OCaml images install the development tools and a system OCaml compiler that is sufficient to build OPAM. These are not intended to be used directly by users since the exact version of the OCaml compiler depends on the distribution involved.
- ocaml/opam: The base OPAM images that provide an initialised OPAM environment with a specific version of the OCaml compiler, and a working
- ocaml/dev: Base images that contain a set of precompiled common libraries, such as Lwt, Core and Merlin.
Most users should primarily use the
ocaml/opam endpoint for development. These images all have multiple Docker tags associated with them, each of which represents a combination of the distribution and OCaml version. For example,
docker pull ocaml/opam:alpine-3.3_ocaml-4.02.3 will obtain the latest Alpine Linux and OCaml 4.02.3 image.
When building Dockerfiles from this image, the [entrypoint](https://docs.docker.com/engine/reference/builder/#entrypoint) to the container runs the command via
opam config exec --, which ensures that all of the locally installed OPAM libraries and environment variables are set.
See the Docker Hub README for the full list of supported distributions and compiler snapshots.
Using these images
The Hub images are rebuilt daily from the latest public OPAM repository. You can therefore use them as the basis for automated testing and local development.
Many continuous integration systems now support Docker containers, and so you can use them to test your software on several distributions.
The ocaml/ocaml-ci-scripts contains shell scripts and documentation about how to activate Travis builds.
Inside there is support for multi-distro builds as well; see this example in OCaml-Dockerfile for an example of how to use it in Travis to build the same package on Debian, Ubuntu, CentOS, Fedora, Alpine and other Linux variants.
If you install Docker on your laptop, you can also run the _same_ tests offline as well as via online CI. This is useful to test things quickly before pushing them to GitHub.
If you want to run the containers on your own servers, then some additional services can be brought up to provide the support:
- ocaml/opam-archive provides a web service running on port 8081 that serves the latest snapshot of the OPAM repository (including all the source code).
- avsm/opam-solver-proxy provides a remote Aspcud solver service. This is necessary for those distributions that do not natively package Aspcud.
Both of these can be run inside a Docker Compose file, or via the Docker Cloud service. For example, a public version of both runs at [opam-archive.f763175e.svc.dockerapp.io:8081] for the archive and  for the solver (both load balanced across 5 virtual machines for high availability and load balancing)
Contributing new base images
- See various distros in README. TODO
- Built by calling dockerfile-ocaml and pushing to ocaml/ocaml-dockerfiles and an autobuild on Docker Hub.
New images are most welcome.
- opam depext must work with the distro
- add ocaml-dockerfile support for the new one