docker-compose up
Lab 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 Git Bash, or Windows WSL) at the
/Docker
folder of the course material.To run a Docker container, we first modify the
volumes
section of thedocker-compose.yml
file to map the203b-lecture
,203-hw
, andmimic
folders 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:8787
to 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 Git Bash, or Windows WSL) at the
/Docker
folder of course material. Type
docker build -f Dockerfile.amd64 . -t [DOCKERHUB_USERNAME]/ucla_biostat_203b_2024w
to 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_2024w
to 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_2024w
Run the container:
apptainer shell ucla-biostat-203b-2024w_latest.sif
Not worked out yet.
6 Run Docker container on cloud (TODO)
6.1 Initial set up to push Docker image to GCR (Google Cloud Registry)
Install
Google Cloud CLI
on local machine (laptop or desktop).Initialize the gcloud CLI:
gcloud init
- GCP authentication:
gcloud auth configure-docker -q
- List existing Docker images and tag for gcr:
docker image list
docker tag huazhou/ucla-biostat-203b-2024w gcr.io/biostat-203b-2024-winter/ubuntu-rstudio-server
- Push the image to gcr:
docker push gcr.io/biostat-203b-2024-winter/ubuntu-rstudio-server
6.2 Run Docker container on GCP
Create a GCE (Google Compute Engine) instance
Create a firewall rule
rstudio-server
that opens the8787
port and add Network tagrstudio-server
to the GCE instance.Paste the GCR image name
gcr.io/biostat-203b-2024-winter/ubuntu-rstudio-server
to theContainer image
field of the GCE instance.Input Environment Variables:
PASSWORD: 203b
,ROOT: true
, andDISABLE_AUTH: true
to the GCE instance.Add volume and disks to the GCE instance. I haven’t got the permissions right yet. The
/mnt/mimic
and/home/studio/203b-lecture
appear to be owned byroot
and not writable byrstudio
. (TODO)