Docker

Set up

Go here to install Docker, following the instructions for your particular operating system.
If you don’t have a Docker account create an account when prompted, or go here.
After you install Docker, start up Docker desktop by double clicking on the app. It may take some time to start up.

Get workshop files

Download the files for this activity clicking here: https://github.com/fhdsl/containers-for-scientists-sandbox/archive/refs/heads/main.zip
Put this file on your desktop so it is easily findable.
Double click the zip file (or right click and choose “unzip” or “decompress” to unzip the file.

Activity 1: Pull and run a Docker image

This activity is built so that you will encounter errors that this guide will work you through! Most common container stumbling block is understanding the idea that containers are isolated from your computer

Which means: If your computer has files, software, or anything else. Your container by default does NOT have it unless you do something to get those files and software on there.

We will encounter both an error of when we don’t have a file we need AND an error of when we don’t have a software package we need. We will guide you through what to do when these expected errors occur.

Step 1: Docker pull

We need to get the Docker image we want to use. We do this by “pulling” it.

Run this command in your Terminal or Command Prompt window:

docker pull cansav09/practice-image:1

Step 2: Check what images you have

To see what images we have we can run docker image ls.
We should see cansav09/practice-image:1 show up in the output.

Step 3: Run the docker image to start a container!

Now if want to launch the image for use, we can use docker run to turn it into a container.

docker run cansav09/practice-image:1

To see what containers we have running we have we can run:

docker ps

Step 4: Run a single command

To run stuff interactively from the command line we can do:

docker exec -it <PUT_CONTAINER_ID_HERE> bash

Step 5: Try calling a script

To run a script using the docker container we could just add reference to a script at the end:

docker exec -it <PUT_CONTAINER_ID_HERE> bash run_analysis.sh

BUT! You will find that this command won’t work yet though, why?

bash: run_analysis.sh: No such file or directory

Question: Does our container have all of the same files that our computer has?

This won’t work because the file run_analysis.sh is not a file that our container has. Docker containers do not have all the files that our computer does; they only have the files we add to it.

Activity 1b: Add a volume to the image

Our container is separate from our computer so if we want to use a file we have to attach it using a “volume”.

Step 1: Let’s add our containers-for-scientists-sandbox files

Let’s point a volume to our workshop files so we have them on our container.

Click here for other ways to get files on a container.

If we want to run run_analysis.sh there’s two ways we could get our files on there. - We could download the files we need from online! We could git clone files from a repository or otherwise wget or curl files. - We could add a volume of files that are local to our computer. For this we will use the You’ll -v or volume option. We’ll do this in the next step.

We can specify a particular file path on our computer or give it $PWD Then optionally we can give a : and a file path we’d like this to be stored on on the container. Otherwise it will be stored at the absolute top of the container.

Now we can run:

docker run -v $pwd:/home cansav09/practice-image:1

If you have a windows machine you may have to run this variant instead. This version has a different ${} around the pwd part.

docker run -v ${pwd}:/home cansav09/practice-image:1

Step 2: Retry calling the script

Now we can run the following command but we will have to run docker ps and get the container ID we need to put here.

docker exec -it <REPLACE_WITH_CONTAINER_ID> bash /home/run_analysis.sh

Now we have a new error! What does this mean?

Question: Does our container have all of the same software that our computer has?

Podman

Set up Podman

Go here to install Podman, following the instructions for your particular operating system.
Open up your command line.
Start up Podman by running the following:

podman machine init
podman machine start

Get workshop files

Download the files for this activity clicking here: https://github.com/fhdsl/containers-for-scientists-sandbox/archive/refs/heads/main.zip
Put this file on your desktop so it is easily findable.
Double click the zip file (or right click and choose “unzip” or “decompress” to unzip the file.

Activity 1: Pull and run an image

This activity is built so that you will encounter errors that this guide will work you through! Most common container stumbling block is understanding the idea that containers are isolated from your computer

Which means: If your computer has files, software, or anything else. Your container by default does NOT have it unless you do something to get those files and software on there.

We will encounter both an error of when we don’t have a file we need AND an error of when we don’t have a software package we need. We will guide you through what to do when these expected errors occur.

Step 1: Podman pull

We need to get the Docker image we want to use. We do this by “pulling” it.

Run this command in your Terminal or Command Prompt window:

podman pull cansav09/practice-image:1

Step 2: Check what images you have

To see what images we have we can run podman image ls.
You should see cansav09/practice-image:1 show up in the output.

Step 3: Run the docker image to start a container!

Now if want to launch the image for use, we can use podman run to turn it into a container.

podman run cansav09/practice-image:1

To see what containers we have running we have we can run:

podman ps

Step 4: Run a single command

To run stuff interactively from the command line we can do:

podman exec -it <PUT_CONTAINER_ID_HERE> bash

Step 5: Try calling a script

To run a script using the docker container we could just add reference to a script at the end:

podman exec -it <PUT_CONTAINER_ID_HERE> bash run_analysis.sh

BUT! You will find that this command won’t work yet though, why?

This won’t work because the file run_analysis.sh is not a file that our container has. Docker containers do not have all the files that our computer does; they only have the files we add to it.

bash: run_analysis.sh: No such file or directory

Activity 1b: Add a volume to the image

Our container is separate from our computer so if we want to use a file we have to attach it using a “volume”.

Step 1: Let’s add our containers-for-scientists-sandbox files

Let’s point a volume to our workshop files so we have them on our container.

Click here for other ways to get files on a container. If we want to run run_analysis.sh there’s two ways we could get our files on there. - We could download the files we need from online! We could git clone files from a repository or otherwise wget or curl files.
- We could add a volume of files that are local to our computer. For this we will use the You’ll -v or volume option. We’re going to do this in the next step.

We will specify a particular file path on our computer or give it $pwd Then we can give a : and a file path we’d like this to be stored on on the container. Otherwise it will be stored at the absolute top of the container.

Now we can run:

podman run -v $pwd:/home cansav09/practice-image:1

If you have a windows machine you may have to run this variant instead. This version has a different ${} around the pwd part.

podman run -v ${pwd}:/home cansav09/practice-image:1

Step 2: Retry calling the script

Now we can run:

podman exec -it <REPLACE_WITH_CONTAINER_ID> bash /home/run_analysis.sh

Now we have a new error! What does this mean?

Question: Does our container have all of the same software that our computer has?