Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"default": true,
"line-length": {
"line_length": 100,
"code_blocks": false,
"tables": false
},
"no-inline-html": {
"allowed_elements": [
"details",
"summary"
]
}
}
18 changes: 10 additions & 8 deletions CHEATSHEET.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
Source: https://docs.docker.com/get-started/docker_cheatsheet.pdf
# Source: <https://docs.docker.com/get-started/docker_cheatsheet.pdf>

## General

- [Docker cli](https://docs.docker.com/engine/reference/commandline/cli/) - **Docker CLI** is the command line interface for Docker
- [Docker Desktop](https://docs.docker.com/desktop) - **Docker Desktop** is available for Mac, Linux, and Windows
- [Docker cli](https://docs.docker.com/engine/reference/commandline/cli/) - **Docker CLI** is the
command line interface for Docker
- [Docker Desktop](https://docs.docker.com/desktop) - **Docker Desktop** is available for Mac,
Linux, and Windows
- `docker --help` - Get help with Docker. You can use `--help` on all subcommands
- `docker info` - Display system-wide information
- [Docker Docs](https://docs.docker.com) - Check out our docs for information on using Docker

## Containers

- `docker run --name <container_name> <image_name>` - Create and run a container from an image, with a custom name
- `docker run -p <host_port>:<container_port> <image_name>` - Run a container and publish a container’s port(s) to the host
- `docker run --name <container_name> <image_name>` - Create and run a container from an image,
with a custom name
- `docker run -p <host_port>:<container_port> <image_name>` - Run a container and publish a
container’s port(s) to the host
- `docker run -d <image_name>` - Run a container in the background
- `docker start|stop <container_name> (or <container-id>)` - Start or stop an existing container
- `docker rm <container_name>` - Remove a stopped container
Expand All @@ -30,14 +34,12 @@ Source: https://docs.docker.com/get-started/docker_cheatsheet.pdf
- `docker rmi <image_name>` - Delete an Image
- `docker image prune` - Remove all unused images


## Docker Registries

The default registry is [Docker Hub](https://hub.docker.com), but you can add more registries.


- `docker login -u <username>` - Login into Docker
- `docker push <username>/<image_name>` - Publish an image to Docker Hub
- `docker search <image_name>` - Search Hub for an image
- `docker pull <image_name>` - Pull an image from Docker Hub
- `docker tag <image_name>:<tag> <username>/<image_name>:<tag>` - Tag an image for a registry
- `docker tag <image_name>:<tag> <username>/<image_name>:<tag>` - Tag an image for a registry
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ This workshop will take you from "Hello Docker" to deploying a containerized web

It's going to be a lot of fun!


## Prerequisites

You need to have access to a machine with docker installed.
There are many ways of getting that:
* Click the link above to get a Cloud shell from Google (require login)
* Docker installed on a linux box.

* Click the link above to get a Cloud shell from Google (requires login).
* Docker installed on a linux box.
* Docker desktop installed on a Mac or Windows machine.

## Philosophy


There are a few things you should know about this tutorial before we begin.

This tutorial is designed to be **self-paced** to make the most of your time.
Expand All @@ -26,13 +25,12 @@ The exercises won't always tell you exactly what you need to do.

Instead, it will point you to the right resources (like documentation and blog posts) to find the answer.

Ready to begin?
---------------
## Ready to begin ?

---

Head over to [the first lab](labs/00-getting-started.md) to begin.

## Cheat sheet

For a quick reference of the most common docker commands, see [CHEATSHEET.md](CHEATSHEET.md).


17 changes: 12 additions & 5 deletions labs/00-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ In this section you will install docker.

## Terminology

Throughout these labs, you will see a lot of Docker-specific jargon which might be confusing to some. So before you go further, let's clarify some terminology that is used frequently in the Docker ecosystem.
Throughout these labs, you will see a lot of Docker-specific jargon which might be confusing to some.
So before you go further, let's clarify some terminology that is used frequently in the Docker ecosystem.

*Docker Container*: An isolated, runnable environment that holds everything needed to run an application.
*Docker Image*: A lightweight, standalone package that contains all necessary code, libraries, and dependencies to run an application.
- *Docker daemon* - The background service running on the host that manages building, running and distributing Docker containers.
*Docker Image*: A lightweight, standalone package that contains all necessary code, libraries, and
dependencies to run an application.

- *Docker daemon* - The background service running on the host that manages building, running and
distributing Docker containers.
- *Docker client* - The command line tool that allows the user to interact with the Docker daemon.
- *Docker Hub* - A [docker registry](https://hub.docker.com/explore/) of Docker images. You can think of the registry as a directory of all available Docker images. You'll be using this later in this tutorial.
- *Docker Hub* - A [docker registry](https://hub.docker.com/explore/) of Docker images. You can
think of the registry as a directory of all available Docker images. You'll be using this later
in this tutorial.

## Installing Docker

Depending on what OS you are running, installation is different, but head over to the [Get started](https://www.docker.com/get-started/) website and follow the instructions there.
Depending on what OS you are running, installation is different, but head over to the
[Get started](https://www.docker.com/get-started/) website and follow the instructions there.
12 changes: 7 additions & 5 deletions labs/01-hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ The goal of this scenario is to make you run your first Docker container.
## Terminology

*Docker Container*: An isolated, runnable environment that holds everything needed to run an application.
*Docker Image*: A lightweight, standalone package that contains all necessary code, libraries, and dependencies to run an application.
*Docker Image*: A lightweight, standalone package that contains all necessary code, libraries, and
dependencies to run an application.

## Exercise

Try running a command with Docker:

```
```bash
docker run hello-world
```

Your terminal output should look like this:

```
```bash
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Expand Down Expand Up @@ -49,8 +50,9 @@ For more examples and ideas, visit:

This message shows that your installation appears to be working correctly.

_*Q: So what did this do?*_
**Q: So what did this do?**

Try to run `docker run hello-world` again.

Docker has now already downloaded the image locally, and can therefore execute the container straight away.
Docker has now already downloaded the image locally, and can therefore execute the container
straight away.
75 changes: 44 additions & 31 deletions labs/02-running-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

## Learning Goals


- Run an [Alpine Linux](http://www.alpinelinux.org/) container (a lightweight linux distribution) on your system and get a taste of the `docker run` command.
- Run an [Alpine Linux](http://www.alpinelinux.org/) container (a lightweight linux distribution) on
your system and get a taste of the `docker run` command.

## Introduction

To get started with running your first container from an image, you'll first pull the Alpine Linux image, a lightweight Linux distribution, and then explore various commands to interact with it.
To get started with running your first container from an image, you'll first pull the Alpine Linux
image, a lightweight Linux distribution, and then explore various commands to interact with it.

## Exercise

Expand All @@ -21,14 +22,14 @@ To get started with running your first container from an image, you'll first pul

### Step by step instructions


To get started, let's run the following in our terminal:

* `docker pull alpine`
- `docker pull alpine`

The `pull` command fetches the alpine **image** from the **Docker registry** and saves it in your system. You can use the `docker image ls` command to see a list of all images on your system.
The `pull` command fetches the alpine **image** from the **Docker registry** and saves it in your
system. You can use the `docker image ls` command to see a list of all images on your system.

* `docker image ls`
- `docker image ls`

Expected output (your list of images will look different):

Expand All @@ -42,7 +43,7 @@ hello-world latest 690ed74de00f 5 months ago

Let's run a Docker **container** based on this image.

* `docker run alpine ls -l`
- `docker run alpine ls -l`

Expected output:

Expand All @@ -57,11 +58,12 @@ drwxr-xr-x 5 root root 4096 Mar 2 16:20 lib
......
```

When you run `docker run alpine`, you provided a command (`ls -l`), so Docker started the command specified and you saw the listing.
When you run `docker run alpine`, you provided a command (`ls -l`), so Docker started the command
specified and you saw the listing.

Try run the following:

* `docker run alpine echo "hello from alpine"`
- `docker run alpine echo "hello from alpine"`

Expected output:

Expand All @@ -71,78 +73,89 @@ hello from alpine

<details>
<summary>More Details</summary>
In this case, the Docker client ran the `echo` command in our alpine container and then exited it. If you've noticed, all of that happened pretty quickly. Imagine booting up a virtual machine, running a command and then killing it. Now you know why they say containers are fast!
In this case, the Docker client ran the `echo` command in our alpine container and then exited it.
If you've noticed, all of that happened pretty quickly. Imagine booting up a virtual machine,
running a command and then killing it. Now you know why they say containers are fast!

</details>

Try another command:

* `docker run alpine /bin/sh`
- `docker run alpine /bin/sh`

Wait, nothing happened! Is that a bug?
Wait, nothing happened! Is that a bug?

Well, no.
Well, no.

These interactive shells will exit after running any scripted commands, unless they are run in an interactive terminal - so for this example to not exit, you need to add the parameters `i` and `t`.
These interactive shells will exit after running any scripted commands, unless they are run in
an interactive terminal - so for this example to not exit, you need to add the parameters `i` and `t`.

> :bulb: The flags `-it` are short for `-i -t` which again are the short forms of `--interactive` (Keep STDIN open) and `--tty` (Allocate a terminal).
> :bulb: The flags `-it` are short for `-i -t` which again are the short forms of `--interactive`
> (Keep STDIN open) and `--tty` (Allocate a terminal).

* `docker run -it alpine /bin/sh`
- `docker run -it alpine /bin/sh`

You are inside the container shell and you can try out a few commands like `ls -l`, `uname -a` and others.
You are inside the container shell and you can try out a few commands like `ls -l`, `uname -a` and others.

* Exit out of the container by giving the `exit` command.
- Exit out of the container by giving the `exit` command.

Ok, now it's time to list our containers.
Ok, now it's time to list our containers.

The `docker ps` command shows you all containers that are currently running.

* `docker ps`
- `docker ps`

Expected output:

```
```bash
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
```

Notice that you have no running containers. When you wrote `exit` in the shell, the primary process (`/bin/sh`) stopped. No containers are running, you see a blank line. Let's try a more useful variant, listing all containers, both stopped and started.
Notice that you have no running containers. When you wrote `exit` in the shell, the primary
process (`/bin/sh`) stopped. No containers are running, you see a blank line. Let's try a more
useful variant, listing all containers, both stopped and started.

* `docker ps -a`
- `docker ps -a`

Expected output:

```
```bash
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
36171a5da744 alpine "/bin/sh" 5 minutes ago Exited (0) 2 minutes ago fervent_newton
a6a9d46d0b2f alpine "echo 'hello from alp" 6 minutes ago Exited (0) 6 minutes ago lonely_kilby
ff0a5c3750b9 alpine "ls -l" 8 minutes ago Exited (0) 8 minutes ago elated_ramanujan
c317d0a9e3d2 hello-world "/hello" 34 seconds ago Exited (0) 12 minutes ago stupefied_mcclintock
```

What you see above is a list of all containers that you ran. Notice that the `STATUS` column shows that these containers exited a few minutes ago.
What you see above is a list of all containers that you ran. Notice that the `STATUS` column shows
that these containers exited a few minutes ago.

## Naming your container

Take a look again at the output of the `docker ps -a`:

* `docker ps -a`
- `docker ps -a`

Expected output:

```
```bash
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
36171a5da744 alpine "/bin/sh" 5 minutes ago Exited (0) 2 minutes ago fervent_newton
a6a9d46d0b2f alpine "echo 'hello from alp" 6 minutes ago Exited (0) 6 minutes ago lonely_kilby
ff0a5c3750b9 alpine "ls -l" 8 minutes ago Exited (0) 8 minutes ago elated_ramanujan
c317d0a9e3d2 hello-world "/hello" 34 seconds ago Exited (0) 12 minutes ago stupefied_mcclintock
```

All containers have an **ID** and a **name**.
All containers have an **ID** and a **name**.

Both the ID and name is generated every time a new container spins up with a random seed for uniqueness.

> :bulb: Tip: If you want to assign a specific name to a container then you can use the `--name` option. That can make it easier for you to reference the container going forward.
> :bulb: Tip: If you want to assign a specific name to a container then you can use the `--name`
> option. That can make it easier for you to reference the container going forward.

## Summary

That concludes a whirlwind tour of the `docker run` command which would most likely be the command you'll use most often. It makes sense to spend some time getting comfortable with it. To find out more about `run`, use `docker run --help` to see a list of all flags it supports. As you proceed further, we'll see a few more variants of `docker run`.
That concludes a whirlwind tour of the `docker run` command which would most likely be the
command you'll use most often. It makes sense to spend some time getting comfortable with it. To
find out more about `run`, use `docker run --help` to see a list of all flags it supports.
As you proceed further, we'll see a few more variants of `docker run`.
Loading