From 88ef79f840fe9c1e1eb9251da4a9f2b61347e32b Mon Sep 17 00:00:00 2001 From: Craig Osterhout <103533812+craig-osterhout@users.noreply.github.com> Date: Wed, 1 Oct 2025 08:02:00 -0700 Subject: [PATCH] get-started: update write a dockerfile (#23478) ## Description Current issues: - There are several `package.json` files, so it's ambiguous. - There is already a `Dockerfile`, so it must be deleted if asking the user to create one. Also, the existing Dockerfile has a different image version than the one the user is asked to create. Fixes: - Added step to explore the existing Dockerfile to have a smoother transition into deleting it. - Added step to delete the Dockerfile. - Updated step to specify the exact folder where to create the new Dockerfile. https://deploy-preview-23478--docsdocker.netlify.app/get-started/docker-concepts/building-images/writing-a-dockerfile/#creating-the-dockerfile ## Related issues or tickets https://docker.slack.com/archives/C04BMTUC41E/p1759261212446019 ## Reviews - [ ] Editorial review --------- Signed-off-by: Craig --- .../building-images/writing-a-dockerfile.md | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/content/get-started/docker-concepts/building-images/writing-a-dockerfile.md b/content/get-started/docker-concepts/building-images/writing-a-dockerfile.md index 3e10ca3707..3608f7a7ed 100644 --- a/content/get-started/docker-concepts/building-images/writing-a-dockerfile.md +++ b/content/get-started/docker-concepts/building-images/writing-a-dockerfile.md @@ -79,38 +79,49 @@ Now that you have the project, you’re ready to create the `Dockerfile`. 1. [Download and install](https://www.docker.com/products/docker-desktop/) Docker Desktop. -2. Create a file named `Dockerfile` in the same folder as the file `package.json`. +2. Examine the project. + + Explore the contents of `getting-started-todo-app/app/`. You'll notice that a + `Dockerfile` already exists. It is a simple text file that you can open in + any text or code editor. + +3. Delete the existing `Dockerfile`. + + For this exercise, you'll pretend you're starting from scratch and will + create a new `Dockerfile`. + +4. Create a file named `Dockerfile` in the `getting-started-todo-app/app/` folder. > **Dockerfile file extensions** > > It's important to note that the `Dockerfile` has _no_ file extension. Some editors > will automatically add an extension to the file (or complain it doesn't have one). -3. In the `Dockerfile`, define your base image by adding the following line: +5. In the `Dockerfile`, define your base image by adding the following line: ```dockerfile FROM node:22-alpine ``` -4. Now, define the working directory by using the `WORKDIR` instruction. This will specify where future commands will run and the directory files will be copied inside the container image. +6. Now, define the working directory by using the `WORKDIR` instruction. This will specify where future commands will run and the directory files will be copied inside the container image. ```dockerfile WORKDIR /app ``` -5. Copy all of the files from your project on your machine into the container image by using the `COPY` instruction: +7. Copy all of the files from your project on your machine into the container image by using the `COPY` instruction: ```dockerfile COPY . . ``` -6. Install the app's dependencies by using the `yarn` CLI and package manager. To do so, run a command using the `RUN` instruction: +8. Install the app's dependencies by using the `yarn` CLI and package manager. To do so, run a command using the `RUN` instruction: ```dockerfile RUN yarn install --production ``` -7. Finally, specify the default command to run by using the `CMD` instruction: +9. Finally, specify the default command to run by using the `CMD` instruction: ```dockerfile CMD ["node", "./src/index.js"]