Use Docker with RStudio
Published:
Why Docker?
Recently, I encountered a problem with an R package I wanted to install. However, this package requires a higher version of R than the one currently installed on my system. Due to system limitations, I cannot upgrade R. Therefore, I decided to use Docker, which resolves many of these issues for me.
Step-by-Step Installation
Assuming you have Docker installed, it is straightforward to get the RStudio image from Rocker using Docker:
- Open your terminal.
- In the command line, type:
docker pull rocker/rstudio
(addsudo
if you encounter a permission denied error)docker images
(you should see the repository for rocker/rstudio)
Using RStudio with Docker
- Now that you have the rocker/rstudio image in Docker, you need to create a container using the following command:
docker run -d -p 8787:8787 -e USER=<username> -e PASSWORD=<password> rocker/rstudio
- You can check the Docker containers using:
docker container list
- If you see the container for the rocker/rstudio image, it means you have successfully created the container. (Note: remember the name of your container, as it is important.)
- Open your browser and visit “localhost:8787”; you should see the RStudio server running. Firefox is recommended, as I encountered issues with Google Chrome.
- You can use R as usual. To stop the running container, use:
docker stop <container_name>
- If you want to use your container in the future, simply remember its name. To start your container again, use:
docker start <container_name>