Skip to content

Instantly share code, notes, and snippets.

@echuber2
Last active December 9, 2022 23:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save echuber2/2dd51ab799411cbd4894f8a85a3db52c to your computer and use it in GitHub Desktop.
Save echuber2/2dd51ab799411cbd4894f8a85a3db52c to your computer and use it in GitHub Desktop.
Local tester for Rocker RStudio image on M1 Macs
#!/bin/bash
# Local tester for the PrairieLearn Workspaces version of Rocker. We'd like to
# find out if this truly works on M1 Macs (and why). The macOS version of
# Docker Desktop should handle permissions appropriately here, but this script
# may not work on Windows and Linux. If you are not using macOS, just use
# normal Rocker instead of this script.
# 20220111 Eric Huber
# USAGE INSTRUCTIONS
# 1. Edit the LOCAL_MOUNT variable below to whatever working directory you'd
# like to mount into the container. The session uses /home/rstudio/workspace
# as the working directory, so your mount will be at: /home/rstudio/workspace/rocker-mounted
# 2. Run this script with:
# bash ./pl-rocker-local-test.sh
# 3. You'll see some warnings and errors about s6 that you can ignore,
# and eventually "Starting nginx". Then go here in your browser:
# http://localhost:3939/rstudio
# ---
# Pull the PrairieLearn version of the Rocker image
# (After the first download, comment out this line for faster restarts.)
sudo docker pull prairielearn/workspace-rstudio
# Prepare a local directory to be mounted inside the container read-write
LOCAL_MOUNT="$HOME/rocker-mounted"
mkdir -p "$LOCAL_MOUNT"
sudo docker run -it --rm -v "$LOCAL_MOUNT:/home/rstudio/workspace/rocker-mounted" -p 127.0.0.1:3939:3939 -u 0 prairielearn/workspace-rstudio
@echuber2
Copy link
Author

Supposedly, this works with macOS Monterey 12.1 on an M1 Pro. Docker version 20.10.11, Docker Desktop 4.3.2. Thanks to @barbehenna for testing this.

@echuber2
Copy link
Author

echuber2 commented Jan 11, 2022

Notes:

  • Not sure yet if this works on M1 (non Pro).
  • The startup sequence shows some errors and warnings (even "fatal" ones) about s6, but this is expected and you can ignore it. Hopefully it works anyway. If you finally see "Starting nginx" appear, and it doesn't crash to your terminal, then it is working.
  • Toggling the "new virtualization framework" option in Docker Desktop doesn't seem to affect anything.
  • Toggling the "gRPC FUSE" option in Docker Desktop doesn't seem to affect anything.
  • Docker Desktop for macOS handles the permissions on the mounted directory gracefully, but this may not work in Windows or native Linux. (Don't use this script outside of macOS, just use normal Rocker images.)
  • The security settings on the image are very permissive, so make sure your port 3939 is not accepting incoming connections from the network (allow connections from localhost only). I'm not sure how best to configure macOS' firewall to achieve this. It might be possible to make a derivative of the image with better security for use as an M1-compatible local session.
    • Update: I think -p 127.0.0.1:3939:3939 helps with this a bit (publishing on localhost only).

It would be interesting for the Rocker developers to hear if this works for others on M1. They don't know why this works on M1 when other Rocker RStudio images reportedly fail to launch, but perhaps the limited security model of the image is avoiding problems. (In its original intended use case, this image has security provided by an external hosting environment.)

Also note, I only wrote the Dockerfile for the PrairieLearn version of the image, and I'm not a developer on Rocker or RStudio, so I can't provide in-depth support about this here. It would be best to discuss on Rocker repo issues.

@njudd
Copy link

njudd commented Dec 9, 2022

Works macOS Monterey 12.5 on an M1 14inch pro; Docker version 20.10.17, build 100c70180f

Thanks a mil!

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