42

I am trying to install mono package onto a Docker container, but mono requires git , autoconf, libtool, automake, build-essential , mono-devel, gettext packages.

the problem I am having is that libtool requires libc-dev, and libc-dev requires gcc compiler.

The docker container does not have any compiler installed, but my local machine does.

arcolombo@acolombo:~/Documents/bedgraph_dockerfile$ dpkg --list |grep    compiler
ii  g++                                                                 4:4.8.2-1ubuntu6                                    amd64        GNU C++ compiler
ii  g++-4.8                                                     4.8.2-19ubuntu1                                     amd64        GNU C++ compiler
ii  gcc                                                         4:4.8.2-1ubuntu6                                    amd64        GNU C compiler
ii  gcc-4.8                                                     4.8.2-19ubuntu1                                     amd64        GNU C compiler
ii  hardening-includes                                          2.5ubuntu2.1                                        all          Makefile for enabling compiler flags for security hardening
ii  libllvm3.5:amd64                                            1:3.5-4ubuntu2~trusty2                              amd64        Modular compiler and toolchain technologies, runtime library
ii  libmono-compilerservices-symbolwriter4.0-cil                   3.2.8+dfsg-4ubuntu1.1                               all          Mono.CompilerServices.SymbolWriter library (for CLI 4.0)
ii  libxkbcommon0:amd64                                         0.4.1-0ubuntu1                                      amd64        library interface to the XKB compiler - shared library
ii  mono-mcs                                                    3.2.8+dfsg-4ubuntu1.1                               all          Mono C# 2.0 / 3.0 / 4.0 / 5.0  compiler for CLI 2.0 / 4.0 / 4.5

so my question is , what is the easiest way to get a gcc compiler onto a Docker container? should I just create a volume of these compiler directories into my docker container?

The reason I think I may need it is because I am running a website, and the website executes a docker image directly.

3 Answers 3

47

In your Dockerfile:

FROM ubuntu
# ...
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
    apt-get -y install gcc mono-mcs && \
    rm -rf /var/lib/apt/lists/*
9
  • 1
    what is the difference between RUN apt-get install g++-4.9 ? Apr 19, 2015 at 17:29
  • 1
    what is the difference between mono-mcs, and the instructions found from their mono website, PATH=$PREFIX/bin:$PATH git clone github.com/mono/mono.git cd mono ./autogen.sh --prefix=$PREFIX make make install Apr 19, 2015 at 18:23
  • @arcolombo, in my snipet the GNU C compiler has been installed. Feel free to replace this line with any other compiler you need. If you need the latest g++, just do it. Apr 19, 2015 at 18:48
  • 3
    You should inline DEBIAN_FRONTEND=noninteractive right before apt-get install.... it's bad practice to have it as a docker ENV, because it will persist when you run the container...
    – zbeekman
    Dec 7, 2016 at 0:23
  • 1
    @zbeekman From my point of view it's not very good idea to develop code inside Docker container. It's just not convenient for these purposes. I've built a lot of Docker images to be used in production, and to be honest there were no any problems with DEBIAN_FRONTEND. I would suggest developers to build and run unit-tests on their code inside containers and delete them after build. This is my point of view. Please feel free to post your own answer to this question :) Dec 9, 2016 at 16:28
27

As I understand it, the OP has confused the terminology, and probably meant to ask:

installing a GCC compiler onto a Docker image

My answer starts by addressing the title of the question (regarding containers), then moves on to the intent of the question (regarding images).

If you can run a BASH shell in the container, then you don't need to manipulate a Dockerfile.

Say, for example, you try the hint from the docker run hello-world example:

docker run -it ubuntu bash

Then just run these from the shell in the container...

apt-get update
apt-get install gcc

A key point is that apt-get install in a raw Docker container may not behave as expected if you don't first run apt-get update. Expect to see...

Unable to locate package gcc

The error message when trying to install g++ without apt-get update is even more confusing due to "regex" substitution.


See also: http://www.liquidweb.com/kb/how-to-list-and-attach-to-docker-containers

docker ps -a ## list all available containers

and

docker exec -ti [CONTAINER ID] bash

This live-manipulation approach can also be used to creates images as the OP probably intended. Use docker commit to save your live container as a new image.

1
  • Worked for me ! IMHO this is far simpler than the accepted answer ... Aug 22, 2021 at 11:29
8

You could also grab an official image that already has GCC and/or some/most of the tools you need already installed. The docker store has a lot of official images already setup: https://store.docker.com/search?page_size=99&q=&source=verified

I'm not sure if it's the right mono, but they have a mono image: https://store.docker.com/images/4234a761-444b-4dea-a6b3-31bda725c427?tab=description

And an official GCC image: https://store.docker.com/images/06ad851d-f666-47d3-9ef3-e90535c141ec?tab=description

There's also buildpack-deps if you're going to be building stuff yourself: https://store.docker.com/images/9e56c286-5b40-4838-89fe-fd513c9c3bd6

You can browse by category: https://store.docker.com/search?page_size=99&q=&source=verified

And also directly search docker hub for mono or whatever your needs are: https://hub.docker.com/search/?isAutomated=0&isOfficial=0&page=1&pullCount=0&q=mono&starCount=0

1
  • Just highlighting that, for gcc and other tooling, this one was very helpful: docker pull buildpack-deps:20.04
    – CivFan
    Jun 24, 2021 at 22:46

Your Answer

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

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