Insights for Action

Using Docker for R

Using Docker

I had partitioned my development environment such that I had virtual machines providing:

This basically avoided some package clashes when “tinkering”. There is however some clumsiness (I need lots of PostgreSQL clients all over the place). So the current cunning plan is to run some of this inside Docker.

The first step was adding a GPG key and the docker repositories. I seemed to faff around a bit but I think you just sudo apt-get install docker-ce (I think I tried to install too many small parts, and had to add facilities to enable docker compose up and could have avoided all this if I’d just installed docker-ce). It’s probably worth checking the current installation pages to do this properly.

The second thing I’d forgotten was that I needed to set up groups and permissions sudo usermod -aG docker ${USER} and then log in to be able to use the group.

Finally, when I ran docker compose up it turns out I needed to have already run docker build. I guess this is likely a shortcoming in my compose.yaml. I’d also forgotten that I needed my own .Rprofile under my configuration (although I’ve pre-specified most of the R packages it’s handy to be able to persist any ad hoc installations. I think. Maybe it’s safer not to have that option and to force yourself to only install packages through the installation process).

Anyway, I have a working R installation isolated in a docker container. I can access R directly on the command line via docker exec -it rstudio_paul /bin/bash, but don’t currently get any graphics devices - maybe I need to set it up as an ssh server and access via TRAMP mode on emacs. I think that means running something like the following:

14
15
16
17
18
19
20
21
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:root123' | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]
Share on: