# How do you distribute OCaml docker containers?

**URL:** <https://discuss.ocaml.org/t/how-do-you-distribute-ocaml-docker-containers/8324>\
**Category:** Learning\
**Tags:** docker\
**Created:** [August 18, 2021, 4:10pm UTC](https://discuss.ocaml.org/t/how-do-you-distribute-ocaml-docker-containers/8324 "2021-08-18T16:10:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mudrz](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@mudrz](https://discuss.ocaml.org/u/mudrz)\
**Post date:** [August 18, 2021, 4:10pm UTC](https://discuss.ocaml.org/t/how-do-you-distribute-ocaml-docker-containers/8324/1 "2021-08-18T16:10:06Z")

</div>

Curious how people build and distribute their OCaml apps

For example, do you  
include the source code (like [FrameworkBenchmarks/opium.dockerfile at master · TechEmpower/FrameworkBenchmarks · GitHub](https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/OCaml/opium/opium.dockerfile))

- copy the source code
- build
- distribute the resulting image

or do you use delete the source code?

or do you do something like this [FrameworkBenchmarks/aspcore-mvc-dap-pg-up.dockerfile at master · TechEmpower/FrameworkBenchmarks · GitHub](https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/CSharp/aspnetcore/aspcore-mvc-dap-pg-up.dockerfile) :

- copy the source code to one image
- build
- copy the build to another image  
to both not distribute the source code and keep the image as small as possible?

---

<div class="post-metadata">

**Author:** ![hcarty](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/hcarty/32/1824_2.png) [@hcarty](https://discuss.ocaml.org/u/hcarty)\
**Post date:** [August 18, 2021, 4:49pm UTC](https://discuss.ocaml.org/t/how-do-you-distribute-ocaml-docker-containers/8324/2 "2021-08-18T16:49:28Z")

</div>

I’m not distributing anything publicly with Docker images, but for internal work projects we use the second approach. First a build stage, then copy the compiled binary + any runtime dependencies to a more minimal runtime image. Multistage builds thankfully make this pretty straightforward, as shown in the example you linked to.

That said, including the a complete suite of build and development dependencies in an image can be very helpful to share a consistent build environment with other developers or across systems.

---

<div class="post-metadata">

**Author:** ![lambda\_foo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lambda_foo/32/275_2.png) [@lambda\_foo](https://discuss.ocaml.org/u/lambda_foo)\
**Post date:** [August 19, 2021, 5:18am UTC](https://discuss.ocaml.org/t/how-do-you-distribute-ocaml-docker-containers/8324/3 "2021-08-19T05:18:13Z")

</div>

The last option for our work with ocaml-ci see [ocaml-ci/Dockerfile at master · ocurrent/ocaml-ci · GitHub](https://github.com/ocurrent/ocaml-ci/blob/master/Dockerfile) and [GitHub - ocurrent/ocaml-ci: A CI for OCaml projects](https://github.com/ocurrent/ocaml-ci/)

In Dockerfile:

1. Lines 1 - 34 do the setup, copy and building
2. Lines 34 - 55 produce an image
3. That image gets uploaded to [hub.docker.com](http://hub.docker.com) as [Docker Hub](https://hub.docker.com/r/ocurrent/ocaml-ci-service)
