Skip to content

Instantly share code, notes, and snippets.

@epinna
Last active January 17, 2019 10:24
Show Gist options
  • Save epinna/cab660de30f3d81a2974c524155a50ab to your computer and use it in GitHub Desktop.
Save epinna/cab660de30f3d81a2974c524155a50ab to your computer and use it in GitHub Desktop.
Playground docker image

Disposable playground environment

Build

make build

Usage

make [run] [PORT_MAPPING=<container_port>:<host_port>]

The default Makefile rule (try) runs a disposable docker container, use run to keep the container.

PORT_MAPPING defaults to 80:8000.

/tmp/playground is mapped to ~user/playground.

TODO ...

For macOS

Use DISPLAY=$ip:0 after starting XQartz. Possibly use xhost + $ip on the host.

FROM ubuntu:latest
ARG LOCALE=en_US
ARG CHARMAP=UTF-8
ARG DEBIAN_FRONTEND=noninteractive
RUN dpkg --add-architecture i386
RUN apt-get update && apt-get --yes dist-upgrade && apt-get install --yes --no-install-recommends \
autoconf \
apache2 \
bash-completion \
bsdmainutils \
build-essential \
ca-certificates \
curl \
git \
less \
locales \
nano \
netcat \
vim \
net-tools \
openssh-client \
php \
procps \
tmux \
unrar-free \
unzip \
sudo \
wget \
software-properties-common
# Install Java.
RUN \
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
add-apt-repository -y ppa:webupd8team/java && \
apt-get update && \
apt-get install -y oracle-java8-installer && \
rm -rf /var/cache/oracle-jdk8-installer
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
# Install additional libs
RUN apt-get install -y libxext6 libxrender1 libxtst6 libxi6
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN localedef -i ${LOCALE} -f ${CHARMAP} ${LOCALE}.${CHARMAP}
ENV LANG=${LOCALE}.${CHARMAP}
RUN useradd -ms /bin/bash user && echo "user:user" | chpasswd && adduser user sudo
WORKDIR /home/user
ENTRYPOINT ["/bin/bash"]
.PHONY: try run build rm
NAME=playground
IMAGE_NAME=playground-img
PORT_MAPPING=8080:8080
CWD=$(shell pwd)
EXTRA_RUN_ARGS=
run:
xhost +local:docker
-docker run $(REMOVE) -it \
$(EXTRA_RUN_ARGS) \
-p 127.0.0.1:$(PORT_MAPPING) \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v $(CWD)/$(NAME)-home:/home/user/ \
-e DISPLAY=unix$(DISPLAY) \
--privileged \
--shm-size=256m \
--name $(NAME) \
$(IMAGE_NAME)
build:
docker build -t $(IMAGE_NAME) .
try: REMOVE=--rm
try: run
rm:
docker rm -f $(NAME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment