Build and manage RStudio environment with Docker-compose

Introduction

This article summarizes how to build an RStuido environment. I wanted to manage it easily because it was a big deal, so I investigated how to manage it easily with Docker-compose.

reference

I referred to the following page.

blog -Manage RSTUDIO using DOCKER-COMPOSE -Installation of RStudio Server-Data Analysis Study Group

Docker-hub

Environment

About Docker

In this article, I will not explain in detail about Docker and how to install it. (Because there are many other easy-to-understand articles.) This time, we will build the environment using Dockerfile and Docker-compose.

Dockefile Configuration file for creating your own Docker image (like a recipe)

Docker-compose A tool for easily building Docker images and starting containers

Dockerfile On Dockerhub, an image file called Rocker for building an R environment is distributed. Among them, this time we will build the environment based on the image file in which the tidyverse library is already installed. (Because tidyverse libraries are very convenient)

In addition, Japanese fonts will be installed so that garbled characters will not occur even if Japanese is included in the legend such as graphs.


#Base image
FROM rocker/tidyverse:3.6.3

#Switch OS environment to Japanese locale

ENV LANG ja_JP.UTF-8
ENV LC_ALL ja_JP.UTF-8
RUN sed -i '$d' /etc/locale.gen \
  && echo "ja_JP.UTF-8 UTF-8" >> /etc/locale.gen \
    && locale-gen ja_JP.UTF-8 \
    && /usr/sbin/update-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja"
RUN /bin/bash -c "source /etc/default/locale"
RUN ln -sf  /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

#Install Japanese fonts
RUN apt-get update && apt-get install -y \
  fonts-ipaexfont \
  fonts-noto-cjk

Docker-compose Next is Docker-compose. Set any password in "environment". Also, in "volumes", the directory "R" that exists in the current directory of the host OS is mounted. By mounting, the files created in RStudio will remain there, and even if you delete the container, the files will not disappear.


version: '3'
services:
  rstudio:
    build: .
    image: tidyverse:3.6.3_jp
    container_name: tidyverse_jp
    environment: 
      #Set any password
      - PASSWORD=*****
    ports:
      - 8787:8787
    volumes:
      - ./R:/home/rstudio
    tty: true
    stdin_open: true

Launching the environment

You can start the environment just by executing the following command in the directory where the Dockerfile and Docker-compose files created earlier exist.

docker-compose up -d

You can connect to the RS studio environment by launching the container and entering the browser with the URL below. http://localhost:8787 The default Username is "rstudio", and you can sign in by entering the Password you set earlier.

スクリーンショット 2020-12-31 11.43.12.png

Executing sample code

Since the Japanese font has been installed, check if there are any garbled characters.

library(ggplot2)
scatter <- ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width)) 
scatter + geom_point(aes(color=Species, shape=Species)) +
  xlab("Iris calyx length") +  ylab("Width of calyx") +
  ggtitle("The length and width of the calyx") 

I was able to confirm that Japanese was plotted without any problems.

スクリーンショット 2020-12-31 11.49.49.png

Next In the future, I would like to upload articles related to R.

Recommended Posts

Build and manage RStudio environment with Docker-compose
Build Nuxt TypeScript + Vuetify environment with docker-compose
Build docker environment with WSL
Build WordPress environment with Docker (Local) and AWS (Production)
Build a Node-RED environment with Docker to move and understand
Build Couchbase local environment with Docker
Build a Node.js environment with Docker
Build a Tomcat 8.5 environment with Pleiades 4.8
Build PlantUML environment with VSCode + Docker
Build environment with vue.js + rails + docker
Build Rails environment with Docker Compose
Create Laravel environment with Docker (docker-compose)
Build jooby development environment with Eclipse
Build docker + laravel environment with laradock
Build Zabbix5.0 with official docker-compose, monitor SNMPTRAP and set Slack notifications
Building Rails 6 and PostgreSQL environment with Docker
Build a PureScript development environment with Docker
Try running MySql and Blazor with docker-compose
Build DNS server with CentOS8 and bind
Build a Wordpress development environment with Docker
[Docker] Build Jupyter Lab execution environment with Docker
Build an environment with Docker on AWS
Build TensorFlow operation check environment with Docker
Environment construction summary with rvm and postgresql
How to build Rails 6 environment with Docker
Build a Windows application test environment with Selenium Grid, Appium, and Windows Application Driver
Build a hot reload development environment with Docker-compose using Realize of Go
[Copy and paste] Build a Laravel development environment with Docker Compose Part 2
How to use args :, environment :, env_file: and .env files with docker-compose command
[Copy and paste] Build a Laravel development environment with Docker Compose Participation
Build a bulletin board API with authentication and authorization with Rails 6 # 1 Environment construction
Build a Laravel / Docker environment with VSCode devcontainer
Build a WordPress development environment quickly with Docker
Build and test Java + Gradle applications with Wercker
Build Java environment and output hello world [Beginner]
Build an E2E test environment with Selenium (Java)
Avoid garbled characters and share file system with Docker environment Rstudio (also Docoker-compose)
How to send custom metrics and events to datadog with laravel in docker-compose environment
Build Spring Boot project by environment with Gradle
Build Apache and Tomcat environment with Docker. By the way, Maven & Java cooperation
[Win10] Build a JSF development environment with NetBeans
Rails development environment created with VSCode and devcontainer
How to build API with GraphQL and Rails
Prepare a scraping environment with Docker and Java
Moved to anyenv! (Manage rbenv and nodenv with anyenv)
Build mecab (NEologd dictionary) environment with Docker (ubuntu)
[Rails] How to build an environment with Docker
[First team development ②] Build an environment with Docker
Build a Java development environment with VS Code
Until you build a Nuxt.js development environment with Docker and touch it with VS Code
[Rails] [Docker] Copy and paste is OK! How to build a Rails development environment with Docker
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
Build Elastic Stack with Docker and analyze IIS logs
Build Java development environment with VS Code on Mac
Switch environment with Spring Boot application.properties and @Profile annotation
How to build docker environment with Gradle for intelliJ
Build an environment of Ruby2.7.x + Rails6.0.x + MySQL8.0.x with Docker
Stable development environment construction manual for "Rails6" with "Docker-compose"
Easily build a Vue.js environment with Docker + Vue CLI
I started MySQL 5.7 with docker-compose and tried to connect
Build ruby debug environment with VS Code of Windows 10