docker-compose upLab 3: Docker
Biostat 203B
A customized Docker container provides a self-contained Linux Ubuntu environment for reproducing materials in this course. This tutorial shows how to install Docker Desktop on your computer, run the Docker container, build your own Docker image, and push the image to Docker Hub.
This tutorial assumes that you have already installed R, RStudio, and Git on your computer. If not, please refer to the Lab 1.
1 Install Docker Desktop
Download and install the Docker Desktop https://www.docker.com/products/docker-desktop/.
2 Run a Docker container
Open Terminal (Mac Terminal, Windows WSL, or Windows Git Bash) at the
/Dockerfolder of the course material.To run a Docker container, we first modify the
volumessection of thedocker-compose.ymlfile to map the203b-lecture,203-hw, andmimicfolders on your computer to the home directory in the Ubuntu system in Docker container. Then type
to run the Docker container. This can take up to 10 minutes for Docker to pull the image, depending on internet connection.
- Point your browser to
localhost:8787to connect to the RStudio Server running on the Ubuntu system in the container.
3 Build your own Docker image
Modify the
Dockerfile.amd64(Intel or AMD CPU) orDockerfile.arm64(ARM CPU e.g. Apple M1/M2/M3 CPU) according to your computer architecture.Open Terminal (Mac Terminal, Windows WSL, or Windows Git Bash) at the
/Dockerfolder of course material. Type
docker build -f Dockerfile.amd64 . -t [DOCKERHUB_USERNAME]/ucla_biostat_203b_2025wto build the new Docker image.
4 Push the Docker image to Docker Hub
Create a Docker Hub account at https://hub.docker.com/.
Type
docker push [DOCKERHUB_USERNAME]/ucla_biostat_203b_2025wto push the new Docker image to Docker Hub.
5 Run Docker container on Hoffman2 (TODO)
Follow the instructions here to run the Docker container on Hoffman2.
To pull the image:
apptainer pull docker://huazhou/ucla_biostat_203b_2025wRun the container:
apptainer shell ucla-biostat-203b-2025w_latest.sifNot worked out yet.
6 Run Docker container on cloud (TODO)
In this tutorial, we show how to push the rocker/rstudio Docker image to GCR (Google Cloud Registry) and run the Docker container on GCP (Google Cloud Platform).
6.1 Initial set up to push Docker image to GCR (Google Cloud Registry)
Install
Google Cloud CLIon local machine (laptop or desktop).Initialize the gcloud CLI:
gcloud init- GCP authentication:
gcloud auth configure-docker -q- Download the Docker image
rocker/rstudio:
docker pull --platform linux/amd64 rocker/rstudioWhy do we pull the linux/amd64 image?
- List existing Docker images and tag for gcr:
docker image list
docker tag rocker/rstudio gcr.io/biostat-203b-2025-winter/rstudio- Push the image to gcr:
docker push gcr.io/biostat-203b-2025-winter/rstudio6.2 Run Docker container on GCP
Create a GCE (Google Compute Engine) instance
Create a firewall rule
rstudio-serverthat opens the8787port and add Network tagrstudio-serverto the GCE instance.Paste the GCR image name
gcr.io/biostat-203b-2025-winter/rstudioto theContainer imagefield of the GCE instance.Input Environment Variables:
PASSWORD: 203b,ROOT: true, andDISABLE_AUTH: trueto the GCE instance.Add volume and disks to the GCE instance. I haven’t got the permissions right yet. The
/mnt/mimicand/home/studio/203b-lectureappear to be owned byrootand not writable byrstudio. (TODO)