ยง2024-12-18
Here's a basic Dockerfile to get you started:
# Use an official R image as a base
FROM rocker/r-ver:4.3.1
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV RSTUDIO_VERSION=2023.09.1+386
# Install dependencies and RStudio Server
RUN apt-get update && apt-get install -y \
libcurl4-openssl-dev \
libssl-dev \
libxml2-dev \
sudo \
pandoc \
pandoc-citeproc \
git \
libjpeg-dev \
libxt-dev \
gdebi-core \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Download and install RStudio Server
RUN curl -sSL https://download2.rstudio.org/server/bionic/amd64/rstudio-server-${RSTUDIO_VERSION}-amd64.deb -o rstudio-server.deb \
&& gdebi -n rstudio-server.deb \
&& rm rstudio-server.deb
# Expose the RStudio Server port
EXPOSE 8787
# Set up the user for RStudio Server
RUN useradd -m -s /bin/bash rstudio && echo "rstudio:rstudio" | chpasswd && adduser rstudio sudo
# Set the working directory
WORKDIR /home/rstudio
# Set default user for running the container
USER rstudio
# Start RStudio Server when the container is run
CMD ["/usr/lib/rstudio-server/bin/rserver", "--server-daemonize", "0"]
Explanation of the Dockerfile Base Image:
We use rocker/r-ver:4.3.1, which is an official R image from the Rocker project, designed for R environments. Installing Dependencies:
The RUN command installs system dependencies required for R packages, as well as RStudio Server dependencies (such as libcurl, libssl, libxml2). Downloading and Installing RStudio Server:
The script downloads the .deb file for RStudio Server and installs it using gdebi (which resolves dependencies). Expose Port:
RStudio Server runs by default on port 8787, so we expose that port in the container. Creating the User:
We create a user called rstudio and set the password to rstudio. You may want to change the password and customize this based on your security needs. Running RStudio Server:
The CMD command starts the RStudio Server in non-daemon mode (to keep the container running). Build and Run the Docker Container To build and run this Dockerfile, follow these steps:
Build the Docker Image:
Save the Dockerfile in a directory, then run the following command:
bash Copy code docker build -t rstudio-server . Run the Docker Container:
Once the image is built, you can run the container with:
bash Copy code docker run -d -p 8787:8787 rstudio-server This will start RStudio Server on port 8787. You can access RStudio Server by navigating to http://localhost:8787 in your web browser.
Login using the credentials:
Username: rstudio Password: rstudio (or whatever password you choose). Customization If you want to install additional R packages or dependencies, you can add RUN commands to the Dockerfile to install those packages. To use a different version of RStudio, change the RSTUDIO_VERSION environment variable accordingly.
- ARM64 Dockerfile for RStudio Server Dockerfile
# Use an ARM64-compatible R base image (rocker/r-ver)
FROM rocker/r-ver:4.2.2
# Set the maintainer label
LABEL maintainer="your_email@example.com"
# Install system dependencies, including wget
RUN apt-get update && apt-get install -y \
sudo \
wget \
libcurl4-openssl-dev \
libssl-dev \
libxml2-dev \
libgit2-dev \
libssh2-1-dev \
pandoc \
&& apt-get clean
# Download and install an ARM64 compatible RStudio Server version
# You should replace the URL with the actual ARM64 .deb package URL
RUN wget https://download2.rstudio.org/server/arm64/rstudio-server-2023.x.x-xxx-arm64.deb && \
dpkg -i rstudio-server-2023.x.x-xxx-arm64.deb && \
apt-get install -f && \
rm rstudio-server-2023.x.x-xxx-arm64.deb
# Set up the RStudio user
RUN useradd -m -s /bin/bash rstudio && \
echo "rstudio:rstudio" | chpasswd
# Expose the RStudio Server port
EXPOSE 8787
# Set the working directory
WORKDIR /home/rstudio
# Start the RStudio Server
CMD ["rstudio-server", "start"]