Skip to content

Commit

Permalink
Update week1-introtodocker-cs.Rmd
Browse files Browse the repository at this point in the history
  • Loading branch information
eeholmes authored Jul 30, 2023
1 parent bde442c commit f0edbd1
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions week1-introtodocker-cs.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ Today I will show Docker using GitHub Codespaces since Docker Desktop requires a

# Open a Docker image on a Codespace

[Video of this step](https://youtu.be/ZUCHhflSWpQ)
## Let's run the Docker tutorial image

![](images/youtube-brands.svg) [Video of this step](https://youtu.be/ZUCHhflSWpQ)

## Let's run the Docker tutorial image

Before we willy-nilly run a random container, let's take a look at the image that we will be using: https://hub.docker.com/r/docker/getting-started
Before we run a random container, let's take a look at the image that we will be using: https://hub.docker.com/r/docker/getting-started

![](images/docker-tutorial.png){width="800"}

Expand Down Expand Up @@ -75,7 +75,7 @@ docker run -d -p 80:80 --name test docker/getting-started

### Why is the port listed twice?

It's not exactly. In `80:80`, the second `#` is the port that the application is listening under and your application documentation should tell you if it is listening on a specific port. The first one is the port you want to use in your browser. So we could do `8181:80` and go to our app on port `8181`.
It's not exactly. In `80:80`, the second `#` is the port that the application is listening under and your application documentation should tell you if it is listening on a specific port (or look in the Dockerfile for a line like `EXPOSE 80`). The first one is the port you want to use in your browser. So we could do `8181:80` and go to our app on port `8181`.

The first time it'll download the container. Once it is done, we can see the running container in the ports tab or run

Expand All @@ -99,9 +99,9 @@ Now your application will open in your browser. *It didn't!* Just reload the pag

## Run RStudio within a Codespace

[Video of this step](https://www.youtube.com/watch?v=bzvDaQTqgLg)
![](images/youtube-brands.svg) [Video of this step](https://www.youtube.com/watch?v=bzvDaQTqgLg)

The [Rocker Project](https://rocker-project.org/) makes Docker images for running R and RStudio. Let's spin up RStudio within Codespaces.
The [Rocker Project](https://rocker-project.org/) makes Docker [images](https://rocker-project.org/images/) for running R and RStudio. Let's spin up RStudio within Codespaces.

Go back to the terminal (in your Codespace). From the Rocker Project page, it says to run this to open RStudio:

Expand All @@ -117,6 +117,12 @@ Note, most of those flags are not needed. This works fine. The `-d` is handy jus
docker run -d -e PASSWORD=yourpassword -p 8787:8787 rocker/rstudio
```

As before, go to the ports tab, roll over the local address and click on the globe icon to open. Then login into RStudio with user name `rstudio` and password `yourpassword`. Note you can use the variable `DISABLE_AUTH=true` to disable the login feature:

```
docker run -d -e DISABLE_AUTH=true -p 8787:8787 rocker/rstudio
```

## Connecting RStudio to GitHub

You can now work on code in your RStudio instance, but it is in a container that will disappear (along with your files) as soon as you stop the codespace. And the codespace will stop on its own after inactivity so you definitely want to save your files.
Expand Down Expand Up @@ -172,7 +178,7 @@ docker run \
rocker/geospatial:4.1
```
Once this is ready on port 8181, you can go to your RStudio with R 4.1 and the now expired geo R packages.
Once this is ready on port 8181, you can open RStudio with R 4.1 and the now expired geo R packages.
# Running containers on your computer
Expand All @@ -188,7 +194,9 @@ In this section, I will run the Rocker images on my local computer. For this you
![](images/Docker-tag.png){width="800"}
This means there is a version of the container that will work on your architecture (Apple chip). If you only see `linux/amd64`, you can try emulation but it might not work. To increase success, make sure you have a recent version of Docker installed. To run in emulation mode (Rosetta), you add this to your `docker run` call: `--platform linux/amd64`.
This means there is a version of the container that will work on your architecture (Apple chip). If you only see `linux/amd64`, you can try emulation but it might not work. To increase success, make sure you have a recent version of Docker Decktop installed. To run in emulation mode (Rosetta), you add this to your `docker run` call: `--platform linux/amd64`. If you have MacOS 12.5+, then click the Virtualization Framework setting under Settings in Docker Desktop. See [this](https://levelup.gitconnected.com/docker-on-apple-silicon-mac-how-to-run-x86-containers-with-rosetta-2-4a679913a0d5) info and [this](https://github.com/rocker-org/rocker-versioned2/issues/144) specific to Rocker images.
*Note*, there is a fatal error for M1 Macs with older MacOS versions that will cause Docker Desktop to fail to open if you check the Virtualization Framework setting. Once that happens, you can't uncheck it that so that Docker opens again (because you can't get to Docker Desktop). If that happens, first go to Activity Monitor and force quit Docker and Docker Desktop. Then you have two options: 1) uninstall and reinstall Docker Desktop or 2) type `open ~/Library/Group\ Containers/group.com.docker/settings.json` in a terminal and look for the line `"useVirtualizationFramework": true,` and change that to `"useVirtualizationFramework": false,`.
## Install a way to run containers
Expand All @@ -200,15 +208,15 @@ This means there is a version of the container that will work on your architectu
* [Podman](https://podman.io/) is a more secure option since it does not run containers as root by default. Your organization is more likely to allow Podman.
## Run rocker containers
## Run Rocker containers
Running containers on your local computer is just like (mostly) running containers on your local computer with Docker or Podman. I can start containers with either the desktop app or from a terminal.
**Important!** You have to start the "daemon" before you can run containers using commands in a terminal window. The easy way to do this (without having to remember commands) is to just open the desktop app before you start trying to run commands from the terminal.
### Docker
[Video opening rocker from terminal](https://youtu.be/fv4i0rDcr0s)
![](images/youtube-brands.svg) [Video opening rocker/rstudio from terminal](https://youtu.be/fv4i0rDcr0s)
You can run containers either from the desktop app or from the terminal. In the video I run this code
Expand All @@ -221,16 +229,16 @@ docker run \
rocker/rstudio:latest-daily
```
Then I open my RStudio server from a browser with `http://localhost:8787` (not `https` but `http`) and login as user "test" with password "test".
Then I open my RStudio server from a browser with `http://localhost:8787` (not `https` but `http`) and login as user "test" with password "test". I could use `-e DISABLE_AUTH=true` and remove the `-e USER=test` and `-e PASSWORD=test` parts to turn off the login page.
**Note** 1) If running from the terminal, make sure to open the desktop first to start the docker daemon otherwise you'll get an error about the daemon not running. 2) The rocker apps are listening on port 8787, so make sure the number after the `:` is 8787. The first number is what you will use in the browser. So if you did `8080:8787`, then go to `localhost:8080`.
**Note** 1) If running from the terminal, make sure to open Docker Desktop first to start the docker daemon otherwise you'll get an error about the daemon not running. 2) The rocker apps are listening on port 8787, so make sure the number after the `:` is 8787. The first number is what you will use in the browser. So if you did `8080:8787`, then go to `http://localhost:8080` in your browser (not `https` but `http`) .
### Podman
Running containers with Podman is basically the same, but an important thing to know about Podman is that it replaces the USER variable with "root". It doesn't matter if you pass in `-e USER=something`; it is going to delete that. So you have to log into the RStudio server with "root" as the user.
[Video of running with Podman Desktop](https://youtu.be/Ll4apwgBs_g)
![](images/youtube-brands.svg) [Video of running with Podman Desktop](https://youtu.be/Ll4apwgBs_g)
The video shows me running a container using the Podman Desktop app. I can also run this command from a terminal and do the same thing I did from the desktop app.
Expand All @@ -240,7 +248,6 @@ podman run -d -e PASSWORD=test -p 8787:8787 rocker/rstudio:latest
I open the app by going to `http://localhost:8787` (not `https` but `http`) and logging in as user "root" and password "test" (since I passed in the environment variable for password with `-e PASSWORD=test`).
## Using a versioned rocker image
## Let's spin up a R 4.1 container
Expand All @@ -257,7 +264,7 @@ docker run \
rocker/geospatial:4.1
```
MacOS users with Apple chip add `--platform linux/amd64` so run this
MacOS users with Apple M2 chip read [this thread](https://levelup.gitconnected.com/docker-on-apple-silicon-mac-how-to-run-x86-containers-with-rosetta-2-4a679913a0d5) and [this thread](https://github.com/rocker-org/rocker-versioned2/issues/144) for how to run with Rosetta emulation. Basically you need Ventura and the latest version of Rosetta which you can get with `softwareupdate --install-rosetta`. If you have the M1 chip and MacOS < 12.5, you may be out of luck until an arm64 image is released by Rocker. I was unable to get the Rocker `amd64` images (like geospatial) to connect to the R server on an M1 Mac with BigSur.
```
docker run --platform linux/amd64 \
Expand Down

0 comments on commit f0edbd1

Please sign in to comment.