Skip to content

Commit ca0e85c

Browse files
Replacing Yarn with npm in Docker Workshop (#24012)
- replace old Docker desktop screenshot with the new sidebar - Remove all references to Yarn in the explanation for Part 1 - Show new project directory structure for getting-started-repo - Remove PWD reference from Part 3 - Remove all occurances of Yarn in Part 7 and 8 <!--Delete sections as needed --> ## Description <!-- Tell us what you did and why --> ## Related issues or tickets <!-- Related issues, pull requests, or Jira tickets --> ## Reviews This PR is heavily dependent upon docker/getting-started-app#98 <!-- Notes for reviewers here --> <!-- List applicable reviews (optionally @tag reviewers) --> - [ ] Technical review - [ ] Editorial review - [ ] Product review --------- Co-authored-by: Craig Osterhout <craig.osterhout@docker.com>
1 parent 0440aae commit ca0e85c

9 files changed

Lines changed: 169 additions & 180 deletions

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ Before you can run the application, you need to get the application source code
4242
├── getting-started-app/
4343
│ ├── .dockerignore
4444
│ ├── package.json
45+
│ ├── package-lock.json
4546
│ ├── README.md
4647
│ ├── spec/
4748
│ ├── src/
48-
│ └── yarn.lock
4949
```
5050

5151
## Build the app's image
@@ -58,18 +58,21 @@ To build the image, you'll need to use a Dockerfile. A Dockerfile is simply a te
5858
```dockerfile
5959
# syntax=docker/dockerfile:1
6060

61-
FROM node:lts-alpine
61+
FROM node:24-alpine
6262
WORKDIR /app
6363
COPY . .
64-
RUN yarn install --production
64+
RUN npm install --omit=dev
6565
CMD ["node", "src/index.js"]
6666
EXPOSE 3000
6767
```
68+
This Dockerfile does the following:
6869

69-
This Dockerfile starts off with a `node:lts-alpine` base image, a
70-
light-weight Linux image that comes with Node.js and the Yarn package
71-
manager pre-installed. It copies all of the source code into the image,
72-
installs the necessary dependencies, and starts the application.
70+
- Uses `node:24-alpine` as the base image, a lightweight Linux image with Node.js pre-installed
71+
- Sets `/app` as the working directory
72+
- Copies source code into the image
73+
- Installs the necessary dependencies
74+
- Specifies the command to start the application
75+
- Documents that the app listens on port 3000
7376

7477
2. Build the image using the following commands:
7578

@@ -85,9 +88,9 @@ To build the image, you'll need to use a Dockerfile. A Dockerfile is simply a te
8588
$ docker build -t getting-started .
8689
```
8790

88-
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.
91+
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:24-alpine` image. But, since you didn't have that on your machine, Docker needed to download the image.
8992

90-
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.
93+
After Docker downloaded the image, the instructions from the Dockerfile copied in your application and used `npm` to install your application's dependencies.
9194

9295
Finally, the `-t` flag tags your image. Think of this as a human-readable name for the final image. Since you named the image `getting-started`, you can refer to that image when you run a container.
9396

content/get-started/workshop/04_sharing_app.md

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -81,55 +81,7 @@ Let's try to push the image to Docker Hub.
8181

8282
## Run the image on a new instance
8383

84-
Now that your image has been built and pushed into a registry, try running your app on a brand
85-
new instance that has never seen this container image. To do this, you will use Play with Docker.
86-
87-
> [!NOTE]
88-
>
89-
> Play with Docker uses the amd64 platform. If you are using an ARM based Mac with Apple silicon, you will need to rebuild the image to be compatible with Play with Docker and push the new image to your repository.
90-
>
91-
> To build an image for the amd64 platform, use the `--platform` flag.
92-
> ```console
93-
> $ docker build --platform linux/amd64 -t YOUR-USER-NAME/getting-started .
94-
> ```
95-
>
96-
> Docker buildx also supports building multi-platform images. To learn more, see [Multi-platform images](/manuals/build/building/multi-platform.md).
97-
98-
99-
1. Open your browser to [Play with Docker](https://labs.play-with-docker.com/).
100-
101-
2. Select **Login** and then select **docker** from the drop-down list.
102-
103-
3. Sign in with your Docker Hub account and then select **Start**.
104-
105-
4. Select the **ADD NEW INSTANCE** option on the left side bar. If you don't see it, make your browser a little wider. After a few seconds, a terminal window opens in your browser.
106-
107-
![Play with Docker add new instance](images/pwd-add-new-instance.webp)
108-
109-
5. In the terminal, start your freshly pushed app.
110-
111-
```console
112-
$ docker run -dp 0.0.0.0:3000:3000 YOUR-USER-NAME/getting-started
113-
```
114-
115-
You should see the image get pulled down and eventually start up.
116-
117-
> [!TIP]
118-
>
119-
> You may have noticed that this command binds the port mapping to a
120-
> different IP address. Previous `docker run` commands published ports to
121-
> `127.0.0.1:3000` on the host. This time, you're using `0.0.0.0`.
122-
>
123-
> Binding to `127.0.0.1` only exposes a container's ports to the loopback
124-
> interface. Binding to `0.0.0.0`, however, exposes the container's port
125-
> on all interfaces of the host, making it available to the outside world.
126-
>
127-
> For more information about how port mapping works, see
128-
> [Networking](/manuals/engine/network/_index.md#published-ports).
129-
130-
6. Select the 3000 badge when it appears.
131-
132-
If the 3000 badge doesn't appear, you can select **Open Port** and specify `3000`.
84+
Now that your image has been built and pushed into a registry, you can run your app on any machine that has Docker installed. Try pulling and running your image on another computer or a cloud instance.
13385

13486
## Summary
13587

content/get-started/workshop/06_bind_mounts.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ filesystem you can share with containers. For details about accessing the settin
6565
{{< tab name="Mac / Linux" >}}
6666

6767
```console
68-
$ docker run -it --mount type=bind,src="$(pwd)",target=/src ubuntu bash
68+
$ docker run -it --mount type=bind,src=.,target=/src ubuntu bash
6969
```
7070

7171
{{< /tab >}}
@@ -79,14 +79,14 @@ filesystem you can share with containers. For details about accessing the settin
7979
{{< tab name="Git Bash" >}}
8080

8181
```console
82-
$ docker run -it --mount type=bind,src="/$(pwd)",target=/src ubuntu bash
82+
$ docker run -it --mount type=bind,src="/.",target=/src ubuntu bash
8383
```
8484

8585
{{< /tab >}}
8686
{{< tab name="PowerShell" >}}
8787

8888
```console
89-
$ docker run -it --mount "type=bind,src=$($pwd),target=/src" ubuntu bash
89+
$ docker run -it --mount "type=bind,src=.,target=/src" ubuntu bash
9090
```
9191

9292
{{< /tab >}}
@@ -116,15 +116,15 @@ filesystem you can share with containers. For details about accessing the settin
116116
```console
117117
root@ac1237fad8db:/# cd src
118118
root@ac1237fad8db:/src# ls
119-
Dockerfile node_modules package.json spec src yarn.lock
119+
Dockerfile node_modules package.json package-lock.json spec src
120120
```
121121

122122
6. Create a new file named `myfile.txt`.
123123

124124
```console
125125
root@ac1237fad8db:/src# touch myfile.txt
126126
root@ac1237fad8db:/src# ls
127-
Dockerfile myfile.txt node_modules package.json spec src yarn.lock
127+
Dockerfile myfile.txt node_modules package.json package-lock.json spec src
128128
```
129129

130130
7. Open the `getting-started-app` directory on the host and observe that the
@@ -136,17 +136,17 @@ filesystem you can share with containers. For details about accessing the settin
136136
│ ├── myfile.txt
137137
│ ├── node_modules/
138138
│ ├── package.json
139+
│ ├── package-lock.json
139140
│ ├── spec/
140-
│ ├── src/
141-
│ └── yarn.lock
141+
│ └── src/
142142
```
143143

144144
8. From the host, delete the `myfile.txt` file.
145145
9. In the container, list the contents of the `app` directory once more. Observe that the file is now gone.
146146

147147
```console
148148
root@ac1237fad8db:/src# ls
149-
Dockerfile node_modules package.json spec src yarn.lock
149+
Dockerfile node_modules package.json package-lock.json spec src
150150
```
151151

152152
10. Stop the interactive container session with `Ctrl` + `D`.
@@ -180,23 +180,23 @@ You can use the CLI or Docker Desktop to run your container with a bind mount.
180180

181181
```console
182182
$ docker run -dp 127.0.0.1:3000:3000 \
183-
-w /app --mount type=bind,src="$(pwd)",target=/app \
184-
node:lts-alpine \
185-
sh -c "yarn install && yarn run dev"
183+
-w /app --mount type=bind,src=.,target=/app \
184+
node:24-alpine \
185+
sh -c "npm install && npm run dev"
186186
```
187187

188188
The following is a breakdown of the command:
189189
- `-dp 127.0.0.1:3000:3000` - same as before. Run in detached (background) mode and
190190
create a port mapping
191191
- `-w /app` - sets the "working directory" or the current directory that the
192192
command will run from
193-
- `--mount type=bind,src="$(pwd)",target=/app` - bind mount the current
193+
- `--mount type=bind,src=.,target=/app` - bind mount the current
194194
directory from the host into the `/app` directory in the container
195-
- `node:lts-alpine` - the image to use. Note that this is the base image for
195+
- `node:24-alpine` - the image to use. Note that this is the base image for
196196
your app from the Dockerfile
197-
- `sh -c "yarn install && yarn run dev"` - the command. You're starting a
198-
shell using `sh` (alpine doesn't have `bash`) and running `yarn install` to
199-
install packages and then running `yarn run dev` to start the development
197+
- `sh -c "npm install && npm run dev"` - the command. You're starting a
198+
shell using `sh` (alpine doesn't have `bash`) and running `npm install` to
199+
install packages and then running `npm run dev` to start the development
200200
server. If you look in the `package.json`, you'll see that the `dev` script
201201
starts `nodemon`.
202202

@@ -226,23 +226,23 @@ You can use the CLI or Docker Desktop to run your container with a bind mount.
226226

227227
```powershell
228228
$ docker run -dp 127.0.0.1:3000:3000 `
229-
-w /app --mount "type=bind,src=$pwd,target=/app" `
230-
node:lts-alpine `
231-
sh -c "yarn install && yarn run dev"
229+
-w /app --mount "type=bind,src=.,target=/app" `
230+
node:24-alpine `
231+
sh -c "npm install && npm run dev"
232232
```
233233

234234
The following is a breakdown of the command:
235235
- `-dp 127.0.0.1:3000:3000` - same as before. Run in detached (background) mode and
236236
create a port mapping
237237
- `-w /app` - sets the "working directory" or the current directory that the
238238
command will run from
239-
- `--mount "type=bind,src=$pwd,target=/app"` - bind mount the current
239+
- `--mount "type=bind,src=.,target=/app"` - bind mount the current
240240
directory from the host into the `/app` directory in the container
241-
- `node:lts-alpine` - the image to use. Note that this is the base image for
241+
- `node:24-alpine` - the image to use. Note that this is the base image for
242242
your app from the Dockerfile
243-
- `sh -c "yarn install && yarn run dev"` - the command. You're starting a
244-
shell using `sh` (alpine doesn't have `bash`) and running `yarn install` to
245-
install packages and then running `yarn run dev` to start the development
243+
- `sh -c "npm install && npm run dev"` - the command. You're starting a
244+
shell using `sh` (alpine doesn't have `bash`) and running `npm install` to
245+
install packages and then running `npm run dev` to start the development
246246
server. If you look in the `package.json`, you'll see that the `dev` script
247247
starts `nodemon`.
248248

@@ -273,8 +273,8 @@ You can use the CLI or Docker Desktop to run your container with a bind mount.
273273
```console
274274
$ docker run -dp 127.0.0.1:3000:3000 ^
275275
-w /app --mount "type=bind,src=%cd%,target=/app" ^
276-
node:lts-alpine ^
277-
sh -c "yarn install && yarn run dev"
276+
node:24-alpine ^
277+
sh -c "npm install && npm run dev"
278278
```
279279

280280
The following is a breakdown of the command:
@@ -284,11 +284,11 @@ You can use the CLI or Docker Desktop to run your container with a bind mount.
284284
command will run from
285285
- `--mount "type=bind,src=%cd%,target=/app"` - bind mount the current
286286
directory from the host into the `/app` directory in the container
287-
- `node:lts-alpine` - the image to use. Note that this is the base image for
287+
- `node:24-alpine` - the image to use. Note that this is the base image for
288288
your app from the Dockerfile
289-
- `sh -c "yarn install && yarn run dev"` - the command. You're starting a
290-
shell using `sh` (alpine doesn't have `bash`) and running `yarn install` to
291-
install packages and then running `yarn run dev` to start the development
289+
- `sh -c "npm install && npm run dev"` - the command. You're starting a
290+
shell using `sh` (alpine doesn't have `bash`) and running `npm install` to
291+
install packages and then running `npm run dev` to start the development
292292
server. If you look in the `package.json`, you'll see that the `dev` script
293293
starts `nodemon`.
294294

@@ -318,23 +318,23 @@ You can use the CLI or Docker Desktop to run your container with a bind mount.
318318

319319
```console
320320
$ docker run -dp 127.0.0.1:3000:3000 \
321-
-w //app --mount type=bind,src="/$(pwd)",target=/app \
322-
node:lts-alpine \
323-
sh -c "yarn install && yarn run dev"
321+
-w //app --mount type=bind,src="/.",target=/app \
322+
node:24-alpine \
323+
sh -c "npm install && npm run dev"
324324
```
325325

326326
The following is a breakdown of the command:
327327
- `-dp 127.0.0.1:3000:3000` - same as before. Run in detached (background) mode and
328328
create a port mapping
329329
- `-w //app` - sets the "working directory" or the current directory that the
330330
command will run from
331-
- `--mount type=bind,src="/$(pwd)",target=/app` - bind mount the current
331+
- `--mount type=bind,src="/.",target=/app` - bind mount the current
332332
directory from the host into the `/app` directory in the container
333-
- `node:lts-alpine` - the image to use. Note that this is the base image for
333+
- `node:24-alpine` - the image to use. Note that this is the base image for
334334
your app from the Dockerfile
335-
- `sh -c "yarn install && yarn run dev"` - the command. You're starting a
336-
shell using `sh` (alpine doesn't have `bash`) and running `yarn install` to
337-
install packages and then running `yarn run dev` to start the development
335+
- `sh -c "npm install && npm run dev"` - the command. You're starting a
336+
shell using `sh` (alpine doesn't have `bash`) and running `npm install` to
337+
install packages and then running `npm run dev` to start the development
338338
server. If you look in the `package.json`, you'll see that the `dev` script
339339
starts `nodemon`.
340340

content/get-started/workshop/07_multi_container.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,14 @@ You can now start your dev-ready container.
212212

213213
```console
214214
$ docker run -dp 127.0.0.1:3000:3000 \
215-
-w /app -v "$(pwd):/app" \
215+
-w /app -v ".:/app" \
216216
--network todo-app \
217217
-e MYSQL_HOST=mysql \
218218
-e MYSQL_USER=root \
219219
-e MYSQL_PASSWORD=secret \
220220
-e MYSQL_DB=todos \
221-
node:lts-alpine \
222-
sh -c "yarn install && yarn run dev"
221+
node:24-alpine \
222+
sh -c "npm install && npm run dev"
223223
```
224224

225225
{{< /tab >}}
@@ -228,14 +228,14 @@ You can now start your dev-ready container.
228228

229229
```powershell
230230
$ docker run -dp 127.0.0.1:3000:3000 `
231-
-w /app -v "$(pwd):/app" `
231+
-w /app -v ".:/app" `
232232
--network todo-app `
233233
-e MYSQL_HOST=mysql `
234234
-e MYSQL_USER=root `
235235
-e MYSQL_PASSWORD=secret `
236236
-e MYSQL_DB=todos `
237-
node:lts-alpine `
238-
sh -c "yarn install && yarn run dev"
237+
node:24-alpine `
238+
sh -c "npm install && npm run dev"
239239
```
240240

241241
{{< /tab >}}
@@ -250,23 +250,23 @@ You can now start your dev-ready container.
250250
-e MYSQL_USER=root ^
251251
-e MYSQL_PASSWORD=secret ^
252252
-e MYSQL_DB=todos ^
253-
node:lts-alpine ^
254-
sh -c "yarn install && yarn run dev"
253+
node:24-alpine ^
254+
sh -c "npm install && npm run dev"
255255
```
256256

257257
{{< /tab >}}
258258
{{< tab name="Git Bash" >}}
259259

260260
```console
261261
$ docker run -dp 127.0.0.1:3000:3000 \
262-
-w //app -v "/$(pwd):/app" \
262+
-w //app -v "/.:/app" \
263263
--network todo-app \
264264
-e MYSQL_HOST=mysql \
265265
-e MYSQL_USER=root \
266266
-e MYSQL_PASSWORD=secret \
267267
-e MYSQL_DB=todos \
268-
node:lts-alpine \
269-
sh -c "yarn install && yarn run dev"
268+
node:24-alpine \
269+
sh -c "npm install && npm run dev"
270270
```
271271

272272
{{< /tab >}}
@@ -276,11 +276,13 @@ You can now start your dev-ready container.
276276
using the mysql database.
277277

278278
```console
279-
$ nodemon src/index.js
280-
[nodemon] 2.0.20
279+
[nodemon] 3.1.11
281280
[nodemon] to restart at any time, enter `rs`
282-
[nodemon] watching dir(s): *.*
281+
[nodemon] watching path(s): *.*
282+
[nodemon] watching extensions: js,mjs,cjs,json
283283
[nodemon] starting `node src/index.js`
284+
Waiting for mysql:3306.
285+
Connected!
284286
Connected to mysql db at host mysql
285287
Listening on port 3000
286288
```

0 commit comments

Comments
 (0)