3.2 KiB
title | keywords | description | aliases | |
---|---|---|---|---|
How do I run a container? | get started, quick start, intro, concepts | Learn how to build your own image and run it as a container |
|
In this walkthrough, you'll learn the basic steps of building an image and running your own container. This walkthrough uses a sample Node.js application, but it's not necessary to know Node.js.
Before you start, get Docker Desktop.
Step 1: Get the sample application
If you have git, you can clone the repository for the sample application. Otherwise, you can download the sample application. Choose one of the following options.
{{< tabs >}} {{< tab name="Clone with git" >}}
Use the following command in a terminal to clone the sample application repository.
$ git clone https://github.com/docker/welcome-to-docker
{{< /tab >}} {{< tab name="Download" >}}
Download the source and extract it.
{{< button url="https://github.com/docker/welcome-to-docker/archive/refs/heads/main.zip" text="Download the source" >}}
{{< /tab >}} {{< /tabs >}}
Step 2: View the Dockerfile in your project folder
To run your code in a container, the most fundamental thing you need is a
Dockerfile. A Dockerfile describes what goes into a container. This sample already contains a Dockerfile
. For your own projects, you'll need to create your own Dockerfile
. You can open the Dockerfile
in a code or text editor and explore its contents.
Step 3: Build your first image
You always need an image to run a container. In a terminal, run the following commands to build the image. Replace /path/to/welcome-to-docker/
with the path to your welcome-to-docker
directory.
{{< include "open-terminal.md" >}}
$ cd /path/to/welcome-to-docker/
$ 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 4: Run your container
To run your image as a container:
- In Docker Desktop, go to the Images tab.
- Next to your image, select Run.
- Expand the Optional settings.
- In Host port, specify
8089
. - Select Run.
Step 5: View the frontend
You can use Docker Desktop to access your running container. Select the link next to your container in Docker Desktop or go to http://localhost:8089 to view the frontend.
Summary
In this walkthrough, you built your own image and ran it as a container. In addition to building and running your own images, you can run images from Docker Hub.
Related information:
- Deep dive into building images in the Build with Docker guide
Next steps
Continue to the next walkthrough to learn how you can run one of over 100,000 pre-made images from Docker Hub.
{{< button url="./run-hub-images.md" text="Run Docker Hub images" >}}