Get R and RStudio on RHEL/CentOS 7 with Docker

Featured image

You can encounter some trouble installing R and RStudio on CentOS/RHEL. One alternative to avoid those troubles is to use Docker. Docker containers aimed to really simplify your life in some situations. It is a tool you have to have in your pocket.

Install Docker

Reference: Get Docker CE for CentOS

Uninstall old versions

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

Install required packages

sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

Set up the stable Docker repository

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

Install Docker CE

sudo yum install docker-ce

Start Docker

sudo service docker start

Verify that docker is installed correctly by running the hello-world image.

sudo docker run hello-world

Manage Docker as a non-root user

Reference: Post-installation steps for Linux

Add your user to the docker group.

sudo usermod -aG docker $USER

Log out of your session completely and then log back in so that your group membership is re-evaluated.

Start Docker

sudo service docker start

Verify that you can run docker commands without sudo.

docker run hello-world

Install a RStudio Docker container

Search a docker image

docker search rstudio

Check the information on https://hub.docker.com related to image you feel likely to install usually the one having top star rating that is in my case: rocker/rstudio

Everything looking fine, pull this top star Docker image

docker pull rocker/rstudio

Find the relevant installation instruction that was for this one on GitHub : https://github.com/rocker-org/rocker/wiki/Using-the-RStudio-image

.. and follow the described installation process:

docker run -d -p 8787:8787 rocker/rstudio

Visit http://localhost:8787/ in your browser, as the previous command do not specify any username and password, rstudio will be considered by default as password and username.

To define custom ones, instead of the previous command use something like:

docker run -d -p 8787:8787 -e USER=my_username -e PASSWORD=my_password rocker/rstudio

Retrieve the CONTAINER ID:

docker ps -a

That is for me: abf97894d537

To access to the terminal of your container:

docker exec -ti abf97894d537 bash

From the terminal container, you can update it

sudo apt-get update

To stop the container

docker stop abf97894d537

To start the container

docker start abf97894d537

Docker maintenance commands

Delete all your containers

docker rm $(docker ps -a -q)

Delete all your images

docker rmi $(docker images -q)

See also

Monitor SSIS job and package executions

date_range 02/09/2020

Featured image

How to monitor SSIS job and package executions.

Enable network connectivity between Docker containers on CentOS 8

date_range 15/08/2020

Featured image

Enable a network connectivity between Docker containers on CentOS 8.

Setup a GitHub repository to serve your Sphinx documentation

date_range 07/04/2020

Featured image

Sphinx and GitHub provide an efficient and free way to publish your documentation online. Here we describe how to do so.