You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: get-started/run-your-own-container.md
+5-83
Original file line number
Diff line number
Diff line change
@@ -39,89 +39,11 @@ If you don't have git, download the source and extract it.
39
39
</div>
40
40
</div>
41
41
42
-
## Step 2: Create a Dockerfile in your project folder
42
+
## Step 2: Explore the Dockerfile
43
43
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.
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
125
47
126
48
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.
Building the image may take some time. After your image is built, you can view your image in the **Images** tab in Docker Desktop.
133
55
134
-
## Step 5: Run your container
56
+
## Step 4: Run your container
135
57
136
58
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**.
137
59
138
60
{:width="500px"}
139
61
140
-
## Step 6: Verify that your container is running
62
+
## Step 5: Verify that your container is running
141
63
142
64
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.
0 commit comments