Skip to content

Instantly share code, notes, and snippets.

@unkmas
Last active April 4, 2020 02:29
Show Gist options
  • Save unkmas/f28ebb42b40d70db70fb9f337e10103a to your computer and use it in GitHub Desktop.
Save unkmas/f28ebb42b40d70db70fb9f337e10103a to your computer and use it in GitHub Desktop.
Princeton algs course Dockerfile
FROM openjdk:8
# Install algs4 wrapper
RUN mkdir -p /usr/local/algs4 \
&& cd /usr/local/algs4 \
&& curl -O "https://algs4.cs.princeton.edu/code/algs4.jar" \
&& curl -O "https://algs4.cs.princeton.edu/linux/{javac,java}-{algs4,cos226,coursera}" \
&& find ./ -regextype posix-extended -regex '.*(javac|java)-(algs4|cos226|coursera)' -exec sh -c 'chmod 755 $1 && mv $1 /usr/local/bin' - {} \;
# Install findbugs
RUN cd /usr/local/algs4 \
&& curl -O "https://algs4.cs.princeton.edu/linux/findbugs.{zip,xml}" \
&& curl -O "https://algs4.cs.princeton.edu/linux/findbugs-{algs4,cos226,coursera}" \
&& unzip findbugs.zip \
&& find ./ -regextype posix-extended -regex '.*findbugs-(algs4|cos226|coursera)' -exec sh -c 'chmod 755 $1 && mv $1 /usr/local/bin' - {} \; \
&& rm findbugs.zip
# Install pmd
RUN cd /usr/local/algs4 \
&& curl -O "https://algs4.cs.princeton.edu/linux/pmd.{zip,xml}" \
&& curl -O "https://algs4.cs.princeton.edu/linux/pmd-{algs4,cos226,coursera}" \
&& unzip pmd.zip \
&& find ./ -regextype posix-extended -regex '.*pmd-(algs4|cos226|coursera)' -exec sh -c 'chmod 755 $1 && mv $1 /usr/local/bin' - {} \; \
&& rm pmd.zip
# Install checkstyle
RUN cd /usr/local/algs4 \
&& curl -O "https://algs4.cs.princeton.edu/linux/checkstyle.zip" \
&& curl -O "https://algs4.cs.princeton.edu/linux/checkstyle-suppressions.xml" \
&& curl -O "https://algs4.cs.princeton.edu/linux/checkstyle-{algs4,cos226,coursera}.xml" \
&& curl -O "https://algs4.cs.princeton.edu/linux/checkstyle-{algs4,cos226,coursera}" \
&& unzip checkstyle.zip \
&& find ./ -regextype posix-extended -regex '.*checkstyle-(algs4|cos226|coursera)' -exec sh -c 'chmod 755 $1 && mv $1 /usr/local/bin' - {} \; \
&& rm checkstyle.zip
RUN mkdir /usr/src/princeton-algorithms-p1
WORKDIR /usr/src/princeton-algorithms-p1
ENTRYPOINT /bin/bash
# DOCKER_DISPLAY ?= 192.168.1.63:0
build:
docker build -t coursera/princeton-algorithms-p1 .
bash:
docker run -it -e DISPLAY=$(DOCKER_DISPLAY) -v /tmp/.X11-unix:/tmp/.X11-unix -v $(CURDIR):/usr/src/princeton-algorithms-p1 coursera/princeton-algorithms-p1

For X11 forvarding (visualisation)

On linux - just set $DOCKER_DISPLAY to $DISPLAY (or unix$DISPLAY), not tested

On mac:

  • install socat and xquartz:
brew install socat
brew cask install xquartz
  • open xquartz
  • launch socat
socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
  • (in separate session) set up $DOCKER_DISPLAY
export DOCKER_DISPLAY=$(ifconfig|grep -E inet.*broad|awk '{ print $2; }'):0
@unkmas
Copy link
Author

unkmas commented May 22, 2018

@ro31337 missed notification. Yeah, there was extra linebreak. Fixed

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