From 8515030b54e9857e52b45dba9064c50a40fa9226 Mon Sep 17 00:00:00 2001 From: craig-osterhout Date: Tue, 18 Apr 2023 10:32:29 -0700 Subject: [PATCH] update walkthrough --- get-started/run-your-own-container.md | 88 ++------------------------- 1 file changed, 5 insertions(+), 83 deletions(-) diff --git a/get-started/run-your-own-container.md b/get-started/run-your-own-container.md index c1874295f21..150ac0032df 100644 --- a/get-started/run-your-own-container.md +++ b/get-started/run-your-own-container.md @@ -39,89 +39,11 @@ If you don't have git, download the source and extract it. -## 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. - -
-
- -### 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 -``` - -
-
-
- -### 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 -``` - -
-
-
- -## 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**. ![Running an image in Docker Desktop](images/getting-started-run-image.gif){: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.