3

I need to build a "slim" docker image which only contains the mono runtime in order to execute a pre-compiled F# app. In other words, I want to create the leanest possible image for executing mono apps, without any of the additional stuff for compiling/building apps. I am using Ubuntu:16.04 as a my base image (which weighs at around 47MB).

If I try to install mono on top of that image (using apt-get install mono-devel), then the image grows to whopping 500MB. This of course happens because the entire mono development tools are installed.

How can I proceed to only create an image containing the mono runtime? Is there a way installing through apt-get the mono runtime?

3
  • show your Dockerfile, by the way do you do, in only one run, the install and the cleanup? Jul 1, 2017 at 17:03
  • 1
    This image hub.docker.com/r/neoeinstein/mono-alpine weighs only 5 MB you can also use the original image hub.docker.com/r/frolvlad/alpine-mono Jul 1, 2017 at 17:05
  • @user2915097 Yes that was what I was going to do but then I saw that a "glib hack" is mentioned in the link. Not totally sure what that means in practice but I can't rely on a hack for a production environment Jul 1, 2017 at 19:28

1 Answer 1

8

I'm answering the question as it is stated:

How can I proceed to only create an image containing the mono runtime?

For that, the answer is yes. There is a package for just the runtime called mono-runtime. In addition to that, there is an apt option to ignore installing recommended packages (usually docs and other stuff that may not be necessary for a runtime) with --no-install-recommends. Combining the two, we can get down to around 240 MB on the Ubuntu base:

FROM ubuntu
RUN apt update && apt install -qy --no-install-recommends mono-runtime libfsharp-core4.3-cil

Also mentioned in comments, there are some more minimal images based on Alpine linux that may be of interest such as https://hub.docker.com/r/frolvlad/alpine-mono/ (which at the moment is around 200 MB).

2
  • Adding to this a little bit, you can explore the different dists for mono here. Check the Packages files and you'll see what apt-get will process when you try to install a given package. You can use the Packages manifests as a way to see all the different packages for mono, including the mono-runtime and fsharp if you were wanting to compile fsharp.
    – bluescores
    Jul 1, 2017 at 17:23
  • 1
    I neglected to realize that F# may require other dependencies as well. They may be able to get away with installing libfsharp-core4.3-cil in addition to the runtime. I've amended my answer to be more complete specific to F#.
    – Andy Shinn
    Jul 1, 2017 at 17:35

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.