Docker - Jupyter Lab and R Studio Setup

Created by Chia, Jonathan, last modified on Apr 16, 2022

Introduction

With 2 lines of code you can:

Steps

======

0. Install Requirements

See https://docs.docker.com/desktop/

Click on Mac, Windows, or Linux to see instructions for installing system requirements.

Install all requirements.

1. Install Docker


Download Docker Desktop:

https://www.docker.com/get-started

You will see three different tabs:

Containers - virtualized run-time environment where users can isolate applications from the underlying system. Basically where you run the template.

Images - an immutable (unchangeable) file that contains the source code, libraries, dependencies, tools, and other files needed for an application to run. Basically a template.

Volumes - this is where the data is stored.

https://phoenixnap.com/kb/docker-image-vs-container

https://docs.docker.com/storage/volumes/

Note: If Docker is not working, make sure 'virtualization' is enabled in your BIOS.

2. Pull Docker Image


We will now pull pre-built images from these sources:

Open up your command line (in windows you can open up windows powershell).

Run the below code:

R Studio:

docker pull rocker/tidyverse

Jupyter Lab:

docker pull jupyter/tensorflow-notebook

You should now see rocker/tidyverse or jupyter/tensorflow-notebook in your Images:

Note: you can choose to install a different image if you would like. For example, if you don't need tensorflow you can install jupyter/scipy-notebook.

3. Run Docker Image


Now we need to run the image to create a container:

R Studio:

docker run -p 8787:8787 -v r_volume:/app -e PASSWORD=rstudio --name rstudio rocker/tidyverse

-p tells it to run in the browser

-v names the volume

--name names the container

Jupyter Lab:

docker run -p 8888:8888 --name jupyter -v jupyter_volume:/app -e JUPYTER_ENABLE_LAB=yes -it jupyter/tensorflow-notebook

-v names the volume and sets it up

-it makes it interactive

Now the data will be stored in Volumes:

4. Start the Container


Click the Play button:

And then click Open in Browser:

5. Sign On


Jupyter:

If Jupyter Lab asks for a token, look at the command line and you'll see it in one of the outputs.

R Studio:

Username: rstudio

Password: rstudio

If everything was set up correctly, you should see these screens:

Jupyter Lab:

R Studio:

Next Steps

===========

1. Set up Environments:


Set up your environments.

2. Installing Additional Packages:


Jupyter Lab:

Use pip install in the jupyter lab terminal

R Studio:

Use install.packages()

I believe the packages are saved in the volume.

3. Additional Package Installation through Docker Files:


If you want the container to start with certain packages you can use a Docker File to do that.

Don't have an article for this yet, but see here:

https://davetang.org/muse/2021/04/24/running-rstudio-server-with-docker/

https://towardsdatascience.com/how-to-run-jupyter-notebook-on-docker-7c9748ed209f

Additional Resources

See this link:

https://jupyter-docker-stacks.readthedocs.io/en/latest/

Docker Tutorial for R:

https://jsta.github.io/r-docker-tutorial/02-Launching-Docker.html

Setting up Environment in Jupyter:

Set up environment:

python -m venv myenv

Activate environment:

source venv/bin/activate

Set up ipykernel:

pip install ipykernel
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"

Install packages from requirements.txt:

pip freeze > requirements.txt
pip install -r /path/to/requirements.txt

Document generated by Confluence on Apr 09, 2022 16:54

Atlassian

Last updated