Installing an uptodate version of Mono on Ubuntu using docker
This has been really really painful so far! I just want to get a recent build of Mono into my Ubuntu docker container! It seems the Ubuntu distro is ridiculously out of date and I need to get a recent build on so that I can run a ServiceStack API from it.
Here is my docker file:
#DOCKER-VERSION 0.9.1 FROM ubuntu:14.04 ADD . /src RUN cd src RUN sudo bash RUN apt-get -y install git RUN apt-get -y install autoconf RUN apt-get -y install libtool RUN apt-get -y install g++ RUN apt-get -y install gettext RUN apt-get -y install make RUN apt-get -y install mono-complete RUN git clone git://github.com/mono/mono.git /home/mono RUN cd /home/mono RUN ./autogen.sh --prefix=/usr/local RUN make RUN make install CMD ["mono", "/build/Web.Api.exe"]
Rather than building from source I have also tried:
#DOCKER-VERSION 0.9.1 FROM ubuntu:14.04 MAINTAINER wayneo ADD . /src RUN sudo bash RUN apt-get update RUN apt-get -f install RUN apt-get -y -q install wget RUN wget -q http://download.opensuse.org/repositories/home:/tpokorra:/mono/xUbuntu_14.04/Release.key -O- | apt-key add - RUN apt-get remove -y --auto-remove wget RUN sh -c "echo 'deb http://download.opensuse.org/repositories/home:/tpokorra:/mono/xUbuntu_14.04/ /' >> /etc/apt/sources.list.d/mono-opt.list" RUN apt-get -q update RUN apt-get -y -q install mono-opt CMD ["/opt/mono/bin/mono", "/src/build/Web.Api.exe"]
Which also does not work!
Has anyone managed to do this? Surely it should be easier than this?
One Solution collect form web for “Installing an uptodate version of Mono on Ubuntu using docker”
There are a few things here which seem a bit “odd” to me.
First of all, you
sudo bash (to change user you should use the
USER instruction). From the start of your container you will have root access so you do not need to do this.
RUN command you will spawn a new container for that layer, I recommend you make all your
apt-get commands one line like so (although this is not too important):
RUN apt-get -y install git autoconf libtool g++ gettext make mono-complete
(as you’re running
apt-get install from a non interactive environment, I recommend you also set
ENV DEBIAN_FRONTEND noninteractive so you don’t get any prompts.)
It’s likely that with your Ubuntu version the apt sources will be out of date. Just to make sure you can download all your packages correctly I recommend before you do this you run an update before
RUN apt-get update
As mentioned above, each “layer” of the Dockerfile creates a new container, so using
RUN wont work. You should use the
WORKDIR instruction instead to have:
Each step may produce an error when you run
docker build. You should check the output when you build.
With all this in mind I have managed to build mono from Git and it seems to execute. The Dockerfile to get to this point is below (I have taken out your
CMD, be sure to add them). I recommend you check out the Dockerfile reference at https://docs.docker.com/reference/builder/.
Once you have built the container, you can go into bash (at least with the Ubuntu base) by running
docker run -t -i <IMAGE ID> /bin/bash. The image ID will be shown as
Successfully built <ID HERE>. From here you can debug why your image isn’t working correctly.
Lastly it may be worth building
FROM an existing image which has Mono installed. If you wanted to build from https://registry.hub.docker.com/u/thaiphan/mono/ for example, you’d do
ubuntu. You can then also
ADD your own files and add your own
Dockerfile I made from yours with Mono:
FROM ubuntu:14.04 ENV DEBIAN_FRONTEND noninteractive RUN apt-get update RUN apt-get -y install git autoconf libtool g++ gettext make mono-complete RUN git clone git://github.com/mono/mono.git /home/mono WORKDIR /home/mono RUN ./autogen.sh --prefix=/usr/local RUN make && make install