mirror of https://github.com/docker/docs.git
update walkthrough
This commit is contained in:
parent
f08c1fe3d2
commit
8515030b54
|
@ -39,89 +39,11 @@ If you don't have git, download the source and extract it.
|
|||
</div>
|
||||
</div>
|
||||
|
||||
## Step 2: Create a Dockerfile in your project folder
|
||||
## Step 2: Explore the Dockerfile
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a data-toggle="tab" data-target="#mac-linux">Mac / Linux</a></li>
|
||||
<li><a data-toggle="tab" data-target="#windows">Windows</a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div id="mac-linux" class="tab-pane fade in active" markdown="1">
|
||||
|
||||
### Mac / Linux
|
||||
|
||||
In the terminal, run the following commands listed below.
|
||||
|
||||
Change directory to the `welcome-to-docker` directory. Replace `/path/to/welcome-to-docker` with the path to your `welcome-to-docker` directory.
|
||||
```console
|
||||
$ cd /path/to/welcome-to-docker
|
||||
```
|
||||
Create an empty file named `Dockerfile`.
|
||||
```console
|
||||
$ touch Dockerfile
|
||||
```
|
||||
|
||||
<hr>
|
||||
</div>
|
||||
<div id="windows" class="tab-pane fade" markdown="1">
|
||||
|
||||
### Windows
|
||||
|
||||
In the Windows Command Prompt, run the following commands listed below.
|
||||
|
||||
Change directory to the `welcome-to-docker` directory. Replace `\path\to\welcome-to-docker` with the path to your `welcome-to-docker` directory.
|
||||
|
||||
```console
|
||||
$ cd \path\to\welcome-to-docker
|
||||
```
|
||||
Create an empty file named `Dockerfile`.
|
||||
```console
|
||||
$ type nul > Dockerfile
|
||||
```
|
||||
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
## Step 3: Add instructions to your Dockerfile
|
||||
|
||||
Using a text editor or code editor, add the following contents to the Dockerfile:
|
||||
|
||||
```dockerfile
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
# Start your image with a node base image
|
||||
FROM node:18-alpine
|
||||
|
||||
# Create an application directory
|
||||
RUN mkdir -p /app
|
||||
|
||||
# Set the /app directory as the working directory for any command that follows
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the local app package and package-lock.json file to the container
|
||||
COPY package*.json ./
|
||||
|
||||
# Copy local directories to the working directory of our docker image (/app)
|
||||
COPY ./src ./src
|
||||
COPY ./public ./public
|
||||
|
||||
# Install node packages, install serve, build the app, and remove dependencies at the end
|
||||
RUN npm install \
|
||||
&& npm install -g serve \
|
||||
&& npm run build \
|
||||
&& rm -fr node_modules
|
||||
|
||||
# Specify that the application in the container listens on port 3000
|
||||
EXPOSE 3000
|
||||
|
||||
# Start the app using serve command
|
||||
CMD [ "serve", "-s", "build" ]
|
||||
```
|
||||
|
||||
## Step 4: Build your first image
|
||||
## Step 3: Build your first image
|
||||
|
||||
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.
|
||||
|
||||
|
@ -131,13 +53,13 @@ $ docker build -t welcome-to-docker .
|
|||
|
||||
Building the image may take some time. After your image is built, you can view your image in the **Images** tab in Docker Desktop.
|
||||
|
||||
## Step 5: Run your container
|
||||
## Step 4: Run your container
|
||||
|
||||
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**.
|
||||
|
||||
{:width="500px"}
|
||||
|
||||
## Step 6: Verify that your container is running
|
||||
## Step 5: Verify that your container is running
|
||||
|
||||
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.
|
||||
|
||||
|
|
Loading…
Reference in New Issue