Expert advice sought on how to reduce image size

Hello,

I wanted to build a container with the bare minimum required to compile and run c++ programs.

I built it off ubuntu:xenial in the end.

58 {aws-024}setuid-expt: docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
sandbox-cpp         latest              e505e5add9f3        5 hours ago         478MB
ubuntu              xenial              7e87e2b3bf7a        5 weeks ago         117MB

However, it’s almost a whopping half gigabyte.

Here’s my Dockerfile:

FROM        ubuntu:xenial
MAINTAINER  anand

WORKDIR /sandbox

RUN apt-get update \
        && apt-get install -y \
            software-properties-common \
            wget \
        && add-apt-repository -y ppa:ubuntu-toolchain-r/test \
        && apt-get update \
        && apt-get install -y \
            software-properties-common \
            make \
            valgrind \
            g++-4.9 \
        && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 100 \
        && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 100 \
        && apt-get update \
        && rm -rf /var/lib/apt/lists/* \
        && useradd -u 48 apache

I tried some other base images but I couldn’t get the image size much below 400MB.

I see that the base image I’m using (ubuntu:xenial) is listed at 117MB. Does this mean that the c++ compilation environment (and dependencies) amount to over 300MB?

If so, what are the biggest libraries I can delete from the image without impacting the compilation of simple run-of-the mill c++ programs?

Thanks much for any suggestions and recommendations you can share.

&