Skip to content

Commit ba399ec

Browse files
Merge pull request #17137 from craig-osterhout/update-walkthough-dockerfile
Update DD walkthrough
2 parents 4d8fde4 + 8515030 commit ba399ec

File tree

1 file changed

+5
-83
lines changed

1 file changed

+5
-83
lines changed

get-started/run-your-own-container.md

+5-83
Original file line numberDiff line numberDiff line change
@@ -39,89 +39,11 @@ If you don't have git, download the source and extract it.
3939
</div>
4040
</div>
4141

42-
## Step 2: Create a Dockerfile in your project folder
42+
## Step 2: Explore the Dockerfile
4343

44-
To run your code in a container, the most fundamental thing you need is a Dockerfile. A Dockerfile describes what goes into a container. To add a Dockerfile, create a text file called `Dockerfile` with no file extension in the root directory of your project. You can use the following commands to create a Dockerfile.
44+
To run your code in a container, the most fundamental thing you need is a Dockerfile. A Dockerfile describes what goes into a container. Open the sample application in your IDE and then open the `Dockerfile` to explore its contents. Note that this project already has a Dockerfile, but for your own projects you need to create a Dockerfile. A Dockerfile is simply a text file named `Dockerfile` with no file extension.
4545

46-
<ul class="nav nav-tabs">
47-
<li class="active"><a data-toggle="tab" data-target="#mac-linux">Mac / Linux</a></li>
48-
<li><a data-toggle="tab" data-target="#windows">Windows</a></li>
49-
</ul>
50-
<div class="tab-content">
51-
<div id="mac-linux" class="tab-pane fade in active" markdown="1">
52-
53-
### Mac / Linux
54-
55-
In the terminal, run the following commands listed below.
56-
57-
Change directory to the `welcome-to-docker` directory. Replace `/path/to/welcome-to-docker` with the path to your `welcome-to-docker` directory.
58-
```console
59-
$ cd /path/to/welcome-to-docker
60-
```
61-
Create an empty file named `Dockerfile`.
62-
```console
63-
$ touch Dockerfile
64-
```
65-
66-
<hr>
67-
</div>
68-
<div id="windows" class="tab-pane fade" markdown="1">
69-
70-
### Windows
71-
72-
In the Windows Command Prompt, run the following commands listed below.
73-
74-
Change directory to the `welcome-to-docker` directory. Replace `\path\to\welcome-to-docker` with the path to your `welcome-to-docker` directory.
75-
76-
```console
77-
$ cd \path\to\welcome-to-docker
78-
```
79-
Create an empty file named `Dockerfile`.
80-
```console
81-
$ type nul > Dockerfile
82-
```
83-
84-
<hr>
85-
</div>
86-
</div>
87-
88-
## Step 3: Add instructions to your Dockerfile
89-
90-
Using a text editor or code editor, add the following contents to the Dockerfile:
91-
92-
```dockerfile
93-
# syntax=docker/dockerfile:1
94-
95-
# Start your image with a node base image
96-
FROM node:18-alpine
97-
98-
# Create an application directory
99-
RUN mkdir -p /app
100-
101-
# Set the /app directory as the working directory for any command that follows
102-
WORKDIR /app
103-
104-
# Copy the local app package and package-lock.json file to the container
105-
COPY package*.json ./
106-
107-
# Copy local directories to the working directory of our docker image (/app)
108-
COPY ./src ./src
109-
COPY ./public ./public
110-
111-
# Install node packages, install serve, build the app, and remove dependencies at the end
112-
RUN npm install \
113-
&& npm install -g serve \
114-
&& npm run build \
115-
&& rm -fr node_modules
116-
117-
# Specify that the application in the container listens on port 3000
118-
EXPOSE 3000
119-
120-
# Start the app using serve command
121-
CMD [ "serve", "-s", "build" ]
122-
```
123-
124-
## Step 4: Build your first image
46+
## Step 3: Build your first image
12547

12648
An image is like a static version of a container. You always need an image to run a container. Once you have a Dockerfile in your repository, run the following `docker build` command in the project folder to create an image.
12749

@@ -131,13 +53,13 @@ $ docker build -t welcome-to-docker .
13153

13254
Building the image may take some time. After your image is built, you can view your image in the **Images** tab in Docker Desktop.
13355

134-
## Step 5: Run your container
56+
## Step 4: Run your container
13557

13658
To run your image as a container, go to the **Images** tab, and then select **Run** in the **Actions** column of your image. When the **Optional settings** appear, specify the **Host port** number `8089` and then select **Run**.
13759

13860
![Running an image in Docker Desktop](images/getting-started-run-image.gif){:width="500px"}
13961

140-
## Step 6: Verify that your container is running
62+
## Step 5: Verify that your container is running
14163

14264
You can use Docker Desktop to view and access running containers. Go to the **Containers** tab to view your container and select the link in the **Port(s)** column or go to [http://localhost:8089](http://localhost:8089){:target="_blank" rel="noopener" class="_"} to verify that the application is running.
14365

0 commit comments

Comments
 (0)