Skip to content

Commit

Permalink
guides: add walkthroughs (#18609)
Browse files Browse the repository at this point in the history
* add walkthroughs

Signed-off-by: Craig Osterhout <[email protected]>
  • Loading branch information
craig-osterhout authored Nov 16, 2023
1 parent 8bb75fa commit b119b68
Show file tree
Hide file tree
Showing 32 changed files with 756 additions and 5 deletions.
11 changes: 6 additions & 5 deletions content/get-started/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ aliases:
- /windows/step_six/
- /windows/step_three/
- /windows/step_two/
- /get-started/what-is-a-container/
- /get-started/run-your-own-container/
- /get-started/run-docker-hub-images/
- /get-started/publish-your-own-image/
- /get-started/hands-on-overview/
---

This guide contains step-by-step instructions on how to get started with Docker. This guide shows you how to:
Expand All @@ -72,6 +67,12 @@ This guide contains step-by-step instructions on how to get started with Docker.
- Deploy Docker applications using multiple containers with a database.
- Run applications using Docker Compose.

> **Note**
>
> Before diving in, try the 5-minute hands-on
> [walkthroughs](../guides/walkthroughs/_index.md) to get more familiar with
> Docker Desktop.
## What is a container?

A container is a sandboxed process running on a host machine that is isolated from all other processes running on that host machine. That isolation leverages [kernel namespaces and cgroups](https://medium.com/@saschagrunert/demystifying-containers-part-i-kernel-space-2c53d6979504),
Expand Down
36 changes: 36 additions & 0 deletions content/guides/walkthroughs/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Walkthroughs overview
keywords: get started, quick start, intro, concepts
description: Learn how to build, share, and run applications faster with Docker's 5-minute hands-on walkthroughs
grid:
- title: "What is a container?"
description: Explore a running container in Docker Desktop
link: "/guides/walkthroughs/what-is-a-container/"
- title: "How do I run a container?"
description: Learn how to build an image and run it as a container
link: "/guides/walkthroughs/run-a-container/"
- title: "Run Docker Hub images"
description: Access over 100,000 images in Docker Hub and learn how to run them as a container
link: "/guides/walkthroughs/run-hub-images/"
- title: "Run multi-container applications"
description: Use Docker Compose to run multi-container applications
link: "/guides/walkthroughs/multi-container-apps/"
- title: "Persist data between containers"
description: Persist and share data among containers using a named volume
link: "/guides/walkthroughs/persist-data/"
- title: "Access a local folder"
description: Share and access a local folder from a container with a bind mount
link: "/guides/walkthroughs/access-local-folder/"
- title: "Containerize your application"
description: Find out how to containerize your own apps with a single command
link: "/guides/walkthroughs/containerize-your-app/"
- title: "Publish your image"
description: Publish and share you images on Docker Hub
link: "/guides/walkthroughs/publish-your-image/"
aliases:
- /get-started/hands-on-overview/
---

Get introduced to Docker Desktop in these 5-minute hands-on guides.

{{< grid >}}
90 changes: 90 additions & 0 deletions content/guides/walkthroughs/access-local-folder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: Access a local folder from a container
keywords: get started, quick start, intro, concepts
description: Learn how to access a local folder from a container
---

This walkthrough shows you how to access a local folder from a container. To better understand some concepts in this walkthrough, complete the [Run multi-container applications](./multi-container-apps.md) walkthrough first.

Docker isolates all content, code, and data in a container from your local filesystem. By default, containers can't access directories in your local filesystem.

![Data isolation diagram](images/getting-started-isolation.webp?w=400)

Sometimes, you may want to access a directory from your local filesystem. To do this, you can use bind mounts.

Before you start, [get Docker Desktop](../../get-docker.md).

## Step 1: Get the sample application

If you have git, you can clone the repository for the sample application. Otherwise, you can download the sample application. Choose one of the following options.

{{< tabs >}}
{{< tab name="Clone with git" >}}

Use the following command in a terminal to clone the sample application repository.

```console
$ git clone https://github.com/docker/bindmount-apps
```

{{< /tab >}}
{{< tab name="Download" >}}

Download the source and extract it.

{{< button url="https://github.com/docker/bindmount-apps/archive/refs/heads/main.zip" text="Download the source" >}}

{{< /tab >}}
{{< /tabs >}}

## Step 2: Add a bind mount using Compose

Add a bind mount to access data on your system from a container. A bind mount lets you share a directory from your host's filesystem into the container.

![Bind mount diagram](images/getting-started-bindmount.webp?w=400)

To add a bind mount to this project, open the `compose.yaml` file in a code or text editor, and then uncomment the following lines.

```yaml
todo-app:
# ...
volumes:
- ./app:/usr/src/app
- /usr/src/app/node_modules

```

The `volumes` element tells Compose to mount the local folder `./app` to `/usr/src/app` in the container for the `todo-app` service. This particular bind mount overwrites the static contents of the `/usr/src/app` directory in the container and creates what is known as a development container. The second instruction, `/usr/src/app/node_modules`, prevents the bind mount from overwriting the container's `node_modules` directory to preserve the packages installed in the container.

## Step 3: Run the application

In a terminal, run the follow commands to bring up your application. Replace `/path/to/multi-container-app/` with the path to your applications directory.

{{< include "open-terminal.md" >}}

```console
$ cd /path/to/multi-container-app/
```
```console
$ docker compose up -d
```

## Step 4: Develop the application

Now, you can take advantage of the container’s environment while you develop the application on your local system. Any changes you make to the application on your local system are reflected in the container. In your local directory, open `app/views/todos.ejs` in an code or text editor, update the `Enter your task` string, and save the file. Visit or refresh [localhost:3001](https://localhost:3001)⁠ to view the changes.

## Summary

In this walkthrough, you added a bind mount to access a local folder from a container. You can use this to develop faster without having to rebuild your container when updating your code.

Related information:

- Deep dive into [bind mounts](../../storage/bind-mounts.md)
- Learn about using bind mounts in Compose in the [Compose file reference](../../compose/compose-file/_index.md)
- Explore using bind mounts via the CLI in the [Docker run reference](/engine/reference/run/#volume-shared-filesystems)

## Next steps

Continue to the next walkthrough to learn how you can containerize your own application.

{{< button url="./containerize-your-app.md" text="Containerize your app" >}}
58 changes: 58 additions & 0 deletions content/guides/walkthroughs/containerize-your-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: Containerize your application
keywords: get started, quick start, intro, concepts
description: Learn how to containerize your application.
---

When working with containers, you typically need to create a `Dockerfile` to define your image and a `compose.yaml` file to define how to run it.

To help you create these files, Docker Desktop has the `docker init` command. Run this command in a terminal within your project folder. `docker init` creates all the required files to containerize your application. This walkthrough shows you how this works.

Before you start, [get Docker Desktop](../../get-docker.md).

## Step 1: Run the command to create Docker assets

Choose one of your own applications that you would like to containerize, and in a terminal, run the following commands. Replace `/path/to/your/project/` with the directory containing your project.

{{< include "open-terminal.md" >}}

```console
$ cd /path/to/your/project/
```
```console
$ docker init
```

## Step 2: Follow the on-screen prompts

`docker init` walks you through a few questions to configure your project with sensible defaults. Specify your answers and press `Enter`.

## Step 3: Try to run your application

Once you have answered all the questions, run the following commands in a terminal to run your project. Replace `/path/to/your/project/` with the directory containing your project.

```console
$ cd /path/to/your/project/
```
```console
$ docker compose up
```

## Step 4: Update the Docker assets

The `docker init` command tries its best to do the heavy lifting for you, but sometimes there's some assembly required. In this case, you can refer to the [Dockerfile reference⁠](/engine/reference/builder/) and [Compose file reference](/compose/compose-file/)⁠ to learn how to update the files created by `docker init`.

## Summary

In this walkthrough, you learned how to containerize your own application.

Related information:

- Read more about [docker init](../../engine/reference/commandline/init.md)
- Learn more about Docker assets in the [Dockerfile reference⁠](/engine/reference/builder/) and [Compose file reference](/compose/compose-file/)

## Next steps

Continue to the next walkthrough to learn how to publish an application as an image on Docker Hub.

{{< button url="./publish-your-image.md" text="Publish your image" >}}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
116 changes: 116 additions & 0 deletions content/guides/walkthroughs/multi-container-apps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
title: Run multi-container applications
keywords: get started, quick start, intro, concepts
description: Learn how to use Docker to run multi-container applications
---

If you've already completed the [How do I run a container?](./run-a-container.md) walkthrough, you learned that you must start each container individually. Imagine how great it would be if a tool could start multiple containers with a single command. That tool is Docker Compose.

Before you start, [get Docker Desktop](../../get-docker.md).

## Step 1: Get the sample application

If you have git, you can clone the repository for the sample application. Otherwise, you can download the sample application. Choose one of the following options.

{{< tabs >}}
{{< tab name="Clone with git" >}}

Use the following command in a terminal to clone the sample application repository.

```console
$ git clone https://github.com/docker/multi-container-app
```

{{< /tab >}}
{{< tab name="Download" >}}

Download the source and extract it.

{{< button url="https://github.com/docker/multi-container-app/archive/refs/heads/main.zip" text="Download the source" >}}

{{< /tab >}}
{{< /tabs >}}

The sample application is a simple todo application built using ExpressJS and Node.js. The application saves all todos in a MongoDB database. You don't need to know any of these technologies to continue with the walkthrough.

![The sample app architecture](images/getting-started-multi-container.webp?w=400)

## Step 2: Dig into the Compose file

View the files of the sample application. Notice that it has a `compose.yaml` file. This file tells Docker how to run your application. Open the `compose.yaml` file in a code or text editor to view what it contains.

![Viewing the Compose file](images/getting-started-compose.webp?w=400)

## Step 3: Run the application

To run the multi-container application, open a terminal and run the following commands. Replace `/path/to/multi-container-app/` with the path to your applications directory.

{{< include "open-terminal.md" >}}

```console
$ cd /path/to/multi-container-app/
```
```console
$ docker compose up -d
```

## Step 4: View the frontend and add todos

In the **Containers** tab of Docker Desktop, you should now have an application stack with two containers running (the todo-app, and todo-database).

To view the frontend:

1. In Docker Desktop, expand the application stack in **Containers**.
2. Select the link to port **3000** in the **Port(s)** column or open [https://localhost:3000](https://localhost:3000)⁠.

Add some todo tasks in the frontend, and then open [https://localhost:3000](https://localhost:3000) in a new browser tab. Notice that the tasks are still visible.

## Step 5: Develop in your containers

When developing with Docker, you may need to automatically update and preview your running services as you edit and save your code. You can use Docker Compose Watch for this.

To run Compose Watch and see the real-time changes:

1. Open a terminal and run the following commands. Replace `/path/to/multi-container-app/` with the path to your applications directory.
```console
$ cd /path/to/multi-container-app/
```
```console
$ docker compose watch
```
2. Open `app/views/todos.ejs` in a text or code editor, then change the text on line 18.
3. Save the changes in `app/views/todos.ejs`.
4. View your application at [https://localhost:3000](https://localhost:3000) to see the changes in real-time.

## Step 6: Delete everything and start over

Having your configuration stored in a Compose file has another advantage, you can easily delete everything and start over.

To delete the application stack:

1. Open the **Containers** tab of Docker Desktop
2. Select the Delete icon next to your application stack.

![Deleting the application stack](images/getting-started-delete-stack.webp?w=300&border=true)

After you delete the application stack, follow the steps from [Step 3: Run the
application](#step-3-run-the-application) to run the application again. Note
that when you delete the containers and run them again, any todos that you
created don't persist.

## Summary

In this walkthrough, you ran a multi-container application with Docker Compose. You also learned how to develop in containers and how to delete the application stack along with all of the data.

Related information:

- Deep dive into the [Docker Compose manual](../../compose/_index.md)
- Reference Compose commands in the [Docker Compose CLI reference](../../compose/reference/_index.md)
- Explore samples in the [Awesome Compose GitHub repository](https://github.com/docker/awesome-compose)
- Learn how to implement Compose Watch for your projects in [Use Compose Watch](../../compose/file-watch.md)

## Next steps

Continue to the next walkthrough to learn how to persist data even after deleting the application stack.

{{< button url="./persist-data.md" text="Persist data between containers" >}}
Loading

0 comments on commit b119b68

Please sign in to comment.