Skip to content

Commit 1ee6f44

Browse files
committed
get-started: simplify workshop intro, update node version
Signed-off-by: David Karlsson <[email protected]>
1 parent 1ef9019 commit 1ee6f44

File tree

1 file changed

+32
-77
lines changed

1 file changed

+32
-77
lines changed

content/get-started/workshop/02_our_app.md

Lines changed: 32 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
title: Containerize an application
33
weight: 20
44
linkTitle: "Part 1: Containerize an application"
5-
keywords: dockerfile example, Containerize an application, run docker file, running
5+
keywords: |
6+
dockerfile example, Containerize an application, run docker file, running
67
docker file, how to run dockerfile, example dockerfile, how to create a docker container,
78
create dockerfile, simple dockerfile, creating containers
8-
description: Follow this step-by-step guide to learn how to create and run a containerized
9+
description: |
10+
Follow this step-by-step guide to learn how to create and run a containerized
911
application using Docker
1012
aliases:
11-
- /get-started/part2/
12-
- /get-started/02_our_app/
13-
- /guides/workshop/02_our_app/
13+
- /get-started/part2/
14+
- /get-started/02_our_app/
15+
- /guides/workshop/02_our_app/
1416
---
1517

1618
For the rest of this guide, you'll be working with a simple todo
@@ -49,75 +51,28 @@ Before you can run the application, you need to get the application source code
4951

5052
To build the image, you'll need to use a Dockerfile. A Dockerfile is simply a text-based file with no file extension that contains a script of instructions. Docker uses this script to build a container image.
5153

52-
1. In the `getting-started-app` directory, the same location as the `package.json` file, create a file named `Dockerfile`. You can use the following commands to create a Dockerfile based on your operating system.
53-
54-
{{< tabs >}}
55-
{{< tab name="Mac / Linux / Windows (Git Bash)" >}}
56-
57-
In the terminal, run the following commands.
58-
59-
Make sure you're in the `getting-started-app` directory. Replace `/path/to/getting-started-app` with the path to your `getting-started-app` directory.
60-
61-
```console
62-
$ cd /path/to/getting-started-app
63-
```
64-
65-
Create an empty file named `Dockerfile`.
66-
67-
```console
68-
$ touch Dockerfile
69-
```
70-
71-
{{< /tab >}}
72-
{{< tab name="Windows (Command Prompt)" >}}
73-
74-
In the Windows Command Prompt, run the following commands.
75-
76-
Make sure you're in the `getting-started-app` directory. Replace `\path\to\getting-started-app` with the path to your `getting-started-app` directory.
77-
78-
```console
79-
$ cd \path\to\getting-started-app
80-
```
81-
82-
Create an empty file named `Dockerfile`.
83-
84-
```console
85-
$ type nul > Dockerfile
86-
```
87-
88-
{{< /tab >}}
89-
{{< tab name="Windows (PowerShell)" >}}
90-
91-
In PowerShell, run the following commands.
92-
93-
Make sure you're in the `getting-started-app` directory. Replace `\path\to\getting-started-app` with the path to your `getting-started-app` directory.
94-
95-
```console
96-
$ cd \path\to\getting-started-app
97-
```
98-
99-
Create an empty file named `Dockerfile`.
100-
101-
```powershell
102-
$ New-Item -Path . -Name Dockerfile -ItemType File
103-
```
104-
105-
{{< /tab >}}
106-
{{< /tabs >}}
54+
1. In the `getting-started-app` directory, the same location as the
55+
`package.json` file, create a file named `Dockerfile`. You can use the
56+
following commands to create a Dockerfile based on your operating system.
10757

10858
2. Using a text editor or code editor, add the following contents to the Dockerfile:
10959

11060
```dockerfile
11161
# syntax=docker/dockerfile:1
112-
113-
FROM node:18-alpine
62+
63+
FROM node:lts-alpine
11464
WORKDIR /app
11565
COPY . .
11666
RUN yarn install --production
11767
CMD ["node", "src/index.js"]
11868
EXPOSE 3000
11969
```
12070

71+
This Dockerfile starts off with a `node:lts-alpine` base image, a
72+
light-weight Linux image that comes with Node.js and the Yarn package
73+
manager pre-installed. It copies all of the source code into the image,
74+
installs the necessary dependencies, and starts the application.
75+
12176
3. Build the image using the following commands:
12277

12378
In the terminal, make sure you're in the `getting-started-app` directory. Replace `/path/to/getting-started-app` with the path to your `getting-started-app` directory.
@@ -127,11 +82,12 @@ To build the image, you'll need to use a Dockerfile. A Dockerfile is simply a te
12782
```
12883

12984
Build the image.
85+
13086
```console
13187
$ docker build -t getting-started .
13288
```
13389

134-
The `docker build` command uses the Dockerfile to build a new image. You might have noticed that Docker downloaded a lot of "layers". This is because you instructed the builder that you wanted to start from the `node:18-alpine` image. But, since you didn't have that on your machine, Docker needed to download the image.
90+
The `docker build` command uses the Dockerfile to build a new image. You might have noticed that Docker downloaded a lot of "layers". This is because you instructed the builder that you wanted to start from the `node:lts-alpine` image. But, since you didn't have that on your machine, Docker needed to download the image.
13591

13692
After Docker downloaded the image, the instructions from the Dockerfile copied in your application and used `yarn` to install your application's dependencies. The `CMD` directive specifies the default command to run when starting a container from this image.
13793

@@ -146,43 +102,42 @@ Now that you have an image, you can run the application in a container using the
146102
1. Run your container using the `docker run` command and specify the name of the image you just created:
147103

148104
```console
149-
$ docker run -dp 127.0.0.1:3000:3000 getting-started
105+
$ docker run -d -p 127.0.0.1:3000:3000 getting-started
150106
```
151107

152108
The `-d` flag (short for `--detach`) runs the container in the background.
153109
This means that Docker starts your container and returns you to the terminal
154-
prompt. You can verify that a container is running by viewing it in Docker
155-
Dashboard under **Containers**, or by running `docker ps` in the terminal.
110+
prompt.
156111

157-
The `-p` flag (short for `--publish`) creates a port mapping between the host
158-
and the container. The `-p` flag takes a string value in the format of
159-
`HOST:CONTAINER`, where `HOST` is the address on the host, and `CONTAINER` is
160-
the port on the container. The command publishes the container's port 3000 to
161-
`127.0.0.1:3000` (`localhost:3000`) on the host. Without the port mapping,
162-
you wouldn't be able to access the application from the host.
112+
The `-p` flag (short for `--publish`) creates a port mapping between the
113+
host and the container. The `-p` flag takes a string value in the format of
114+
`HOST:CONTAINER`, where `HOST` is the address on the host, and `CONTAINER`
115+
is the port on the container. The command publishes the container's port
116+
3000 to `127.0.0.1:3000` (`localhost:3000`) on the host. Without the port
117+
mapping, you wouldn't be able to access the application from the host.
163118

164119
2. After a few seconds, open your web browser to [http://localhost:3000](http://localhost:3000).
165120
You should see your app.
166121

167122
![Empty todo list](images/todo-list-empty.webp)
168-
169123

170124
3. Add an item or two and see that it works as you expect. You can mark items as complete and remove them. Your frontend is successfully storing items in the backend.
171125

172-
173126
At this point, you have a running todo list manager with a few items.
174127

175128
If you take a quick look at your containers, you should see at least one container running that's using the `getting-started` image and on port `3000`. To see your containers, you can use the CLI or Docker Desktop's graphical interface.
176129

177130
{{< tabs >}}
178131
{{< tab name="CLI" >}}
179132

180-
Run the following `docker ps` command in a terminal to list your containers.
133+
Run the `docker ps` command in a terminal to list your containers.
181134

182135
```console
183136
$ docker ps
184137
```
138+
185139
Output similar to the following should appear.
140+
186141
```console
187142
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
188143
df784548666d getting-started "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 127.0.0.1:3000->3000/tcp priceless_mcclintock
@@ -204,8 +159,8 @@ In this section, you learned the basics about creating a Dockerfile to build an
204159

205160
Related information:
206161

207-
- [Dockerfile reference](/reference/dockerfile/)
208-
- [docker CLI reference](/reference/cli/docker/)
162+
- [Dockerfile reference](/reference/dockerfile/)
163+
- [docker CLI reference](/reference/cli/docker/)
209164

210165
## Next steps
211166

0 commit comments

Comments
 (0)