Skip to content

Instantly share code, notes, and snippets.

@cboettig
Created December 13, 2014 15:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cboettig/fae74f7e551b0e9f0072 to your computer and use it in GitHub Desktop.
Save cboettig/fae74f7e551b0e9f0072 to your computer and use it in GitHub Desktop.
RStudio
#!/bin/bash
PORT=${PORT:=8787}
# Mac/Windows must get this from boot2docker
IP=${IP:="http://localhost"}
# Pull latest version? (Allowed to fail, in case of no internet etc)
docker pull rocker/rstudio || true
# Get the hash for container named rstudio (if it exists)
CONTAINER=$(docker ps -a | grep "rstudio" | cut -f1 -d" ")
# If container exists but has exited, restart,
# If container doesn't exist, launch new container
if [ ! -z "$CONTAINER" ]
then
STOPPED=$(docker ps -a --filter "status=exited" | grep "rstudio" | cut -f1 -d" ")
if [ ! -z "$STOPPED" ]
then
docker restart $STOPPED
fi
else
echo "Starting new RStudio session"
docker run --name rstudio -d -v /home/$USER:/home/rstudio -p $PORT:8787 rocker/hadleyverse
fi
## open browser at assigned port. xdg-open is the linux 'open default application for'
xdg-open $IP:$PORT &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment