Skip to content

Instantly share code, notes, and snippets.

@JCash
Created August 16, 2019 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JCash/c59987a09f86176c63080748dba93516 to your computer and use it in GitHub Desktop.
Save JCash/c59987a09f86176c63080748dba93516 to your computer and use it in GitHub Desktop.
Ubuntu 18 Docker container for building C++
#FROM i386/ubuntu:18.04
FROM ubuntu:18.04
# Base stuff
RUN \
apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository -y ppa:webupd8team/java && \
apt-get update && \
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
apt-get install -y --no-install-recommends \
oracle-java8-installer \
unzip && \
rm -rf /var/cache/oracle-jdk8-installer
# We still use GCC-5: https://askubuntu.com/a/1087368
RUN \
apt-get update && \
apt-get install -y --no-install-recommends \
gcc-5 \
g++-5 \
libssl-dev \
openssl \
libtool \
autoconf \
automake \
build-essential \
uuid-dev \
libxi-dev \
libopenal-dev \
libgl1-mesa-dev \
libglw1-mesa-dev \
freeglut3-dev && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 20 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 20 && \
update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 && \
update-alternatives --set cc /usr/bin/gcc && \
update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30 && \
update-alternatives --set c++ /usr/bin/g++
RUN \
apt-get update && \
apt-get install -y --no-install-recommends \
clang-6.0 && \
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-6.0 1000 && \
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-6.0 1000 && \
update-alternatives --config clang && \
update-alternatives --config clang++
RUN \
apt-get install -y --no-install-recommends \
tofrodos \
cmake \
curl \
tree \
silversearcher-ag \
valgrind \
git \
python2.7 \
python-setuptools && \
ln -s /usr/bin/python2.7 /usr/local/bin/python && \
ln -s /usr/bin/python2.7 /usr/local/bin/python2 && \
sh -c "echo \#\!/usr/bin/env bash > /usr/local/bin/easy_install" && \
sh -c "echo python /usr/lib/python2.7/dist-packages/easy_install.py $\* >> /usr/local/bin/easy_install" && \
chmod +x /usr/local/bin/easy_install
RUN apt-get autoremove
# Add builder user
RUN useradd -r -u 2222 builder && \
mkdir -p /var/builder && \
chown builder: /var/builder && \
chown builder: $(readlink -f /usr/bin/java) && \
chmod +s $(readlink -f /usr/bin/java)
USER builder
WORKDIR /home/builder
RUN mkdir -p /home/builder
@JCash
Copy link
Author

JCash commented Aug 16, 2019

Put these two scripts in the same folder:
build.sh:

#!/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
docker build -t builder/ubuntu ${DIR}/

run.sh:

#!/usr/bin/env bash

DIR=$1
if [ "$DIR" == "" ]; then
    DIR=`pwd`
fi

docker run --rm --name ubuntu --hostname=ubuntu -t -i -v ${DIR}:/home/builder builder/ubuntu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment