How do I run 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.
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.
Use the following command in a terminal to clone the sample application repository.
$ git clone https://github.com/docker/welcome-to-docker
Download the source and extract it.
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.
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
To run Docker commands, you must use a terminal. Based on your operating system, you can open a terminal by doing the following:
For Windows, select the Start Menu, specify
cmd, and then select Command Prompt.
For Mac, select the Launchpad icon in the Dock, specify
Terminalin the search field, then select Terminal.
$ cd /path/to/welcome-to-docker/
$ docker build -t welcome-to-docker .
In the previous command, the
-t flag tags your image with a name,
welcome-to-docker in this case. And the
. lets Docker know where it can find
Building the image may take some time. After your image is built, you can view your image in the Images tab in Docker Desktop.
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
- Select Run.
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:8089open_in_new to view the frontend.
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.
- Deep dive into building images in the Build with Docker guide
Continue to the next walkthrough to learn how you can run one of over 100,000 pre-made images from Docker Hub.