You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: sections/docker-containers.qmd
+30-17
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,11 @@ from: markdown+emoji
12
12
13
13
## Just what is a container?
14
14
15
+
*A container represents an instance of an image that can be run.*
16
+
15
17
And why might I want one? In short, as a very lightweight way to create a reproducible computing environment. Containers have some desirable properties:
16
18
17
-
-**Declarative**: The are defined by a clear procedure making it possible to reliably rebuild an identical container in a variety of environments, promototing reproducibility
19
+
-**Declarative**: Containers are defined by a clear procedure making it possible to reliably rebuild an identical container in a variety of environments, promototing reproducibility
18
20
-**Portable**: Containers are designed to run on a container runtime which works identically across systems, so you can launch a container from a Mac, Linux, or Windows and get the same output every time
19
21
-**Lightweight**: Containers contain only the exact files and data needed for a specific application, without all of the extra operating system baggage found in virtual machines
20
22
-**Scalable**: Containers can be launched multiple times from their source image, and thus can be horizontally scaled across a compute cluster to parallelize operations
@@ -25,7 +27,7 @@ From the following figure, one can see that a container is much more lightweight
25
27
26
28
**Images***An image is a snapshot of a computing environment.* It contains all of the files and data needed to execute a particular application or service, along with the instructions on which service should be run. But it is not executed per se. As a snapshot, an image represents a template that can be used to create one or more containers (each of which is an instantiation of the contents of the image). Images are also built using a layered file system, which allows multiple images to be layered together to create a composite that provides rich services without as much duplication.
27
29
28
-
**Containers***A container represents in instance of an image that can be run.* Containers are executed in a Container Runtime such as [`containerd`](https://containerd.io/) or [Docker Engine](https://docs.docker.com/engine/). Like virtual machines, containers provide mechanisms to create images that can be executed by a container runtime, and which provide stronger isolation among deployments. But they are also more lightweight, as the container only contains the libraries and executables needed to execute a target application, and not an entire guest operating system. This means that applications run with fewer resources, start up and shut down more quickly, and can be migrated easily to other hosts in a network.
30
+
**Containers***A container represents an instance of an image that can be run.* Containers are executed in a Container Runtime such as [`containerd`](https://containerd.io/) or [Docker Engine](https://docs.docker.com/engine/). Like virtual machines, containers provide mechanisms to create images that can be executed by a container runtime, and which provide stronger isolation among deployments. But they are also more lightweight, as the container only contains the libraries and executables needed to execute a target application, and not an entire guest operating system. This means that applications run with fewer resources, start up and shut down more quickly, and can be migrated easily to other hosts in a network.
29
31
30
32
::: {.callout-note}
31
33
@@ -39,6 +41,32 @@ The [Docker](https://docker.com) system was one of the first widespread implemen
39
41
40
42
:::
41
43
44
+
## Installing Rancher Desktop
45
+
46
+
::: {layout="[[80,20]]"}
47
+
48
+
Working with docker or containers requires a container runtime. Whether you're on a Mac, Windows, or Linux machine, you can run containers through a variety of different runtime systems. One of the nicest lately is [Rancher Desktop](https://rancherdesktop.io/). Install the binary for your platform, and then after it starts, open the Preferences dialog to configure it.
49
+
50
+

51
+
52
+
:::
53
+
54
+
First, under the `Virtual Machine` tab, configure it to use a reasonable amount of your local machine's resources, say about 50 of the CPUs and memory. Second, deselect "Kubernetes" to disable the kubernetes distribution, which takes up a lot of resources if you're not using it.
55
+
56
+
:::{layout-ncol="2"}
57
+
58
+

59
+
60
+

61
+
62
+
:::
63
+
64
+
There are many different tools you can use with docker, including the `docker` client tool, and the `containerd` ecosystem using `nerdctl` as a client tool. Both the `docker` client command and the `nerdctl` command share the same command syntax.
65
+
66
+
## Container and Image portability
67
+
68
+
Images are portable across container runtimes that share the same architecture (e.g., all ARM processors, or x86 processors). This makes it easy to launch and run a container by downloading an image for your architecture, and executing it in a container runtime like `containerd` or `dockerd`. While we will be working on your local Rancher Desktop instance, images you build could also be run on other hosts, such as a linux server, or on a cluster of servers, if they were built for that architecture and have `containerd` installed. Because the container runtime is typically run as the `root` or administrative user, many high-performance computing centers will only expose container runtimes such as [Apptainer](https://apptainer.org/), which supports a more sophisticated security model, or [Kubernetes](https://kubernetes.io), which creates a fully-featured orchestration system.
69
+
42
70
## Hands-on with Containers and Docker
43
71
44
72
Let's get started. At it's simplest, you can use docker to run an image that somebody else created. Let's do that with a simple Hello World app. Open a terminal (on a machine with docker installed), and run:
@@ -557,19 +585,4 @@ Putting it all together, you can use the docker client tool to build an image fr
557
585
Shell on running containers
558
586
-`docker exec -it container1 -- bash`
559
587
560
-
## Exercise
561
-
562
-
- Optional?
563
-
564
-
## Bonus info: Running containers locally
565
-
566
-
Working with docker or containers requires a container runtime. If you're on a Mac or Windows machine, you can run containers through a variety of different runtime systems. One of the nicest lately is [Rancher Desktop](https://rancherdesktop.io/). Install the binary for you platform, and then after it starts, enter the configuration Preferences, and then deselect "Kubernetes" to disable the kubernetes distribution, which takes up a lot of resources if you're not using it.
567
-
568
-

569
-
570
-
There are many different tools you can use with docker, including the `docker` client tool, and the `containerd` ecosystem using `nerdctl` as a client tool. Both the `docker` command and the `nerdctl` command share the same commands. A few quick example commands one might use in the docker ecosystem:
571
-
572
-
-`docker pull python:3.9`: to grab an existing python image from the DockerHub repository
573
-
-`docker run -it python:3.9 -- python`: to start a standard python interpreter
574
-
-`docker build`: to build a new image from a Dockerfile configuration file
0 commit comments