Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Running a Downloaded Image | Working with Docker Images
Docker Essentials

bookRunning a Downloaded Image

Launching Containers from Images

Launching containers from images is a fundamental part of working with Docker. To do this, you use the docker run command, which creates and starts a new container based on a specified image.

The general syntax for this command is:

docker run [OPTIONS] IMAGE [COMMAND]

Some of the most common options include:

  • -d: Runs the container in detached mode (in the background);
  • -p: Maps ports between your host and the container;
  • --name: Assigns a custom name to your container;
  • -it: Runs the container interactively, allowing you to use a shell inside the container.

Running the following command starts a new Ubuntu container and provides an interactive shell inside it:

docker run -p 8080:80 nginx

The -p flag maps the container’s internal port 80 to port 8080 on your local machine.

Once the container is running, you can open your browser and go to:

http://localhost:8080

You will see Nginx running at this address. Notice that nothing is running directly on your computerβ€”everything is running inside Docker.

Container Lifecycle: Starting, Stopping, and Removing Containers

Once a container has been started, it goes through a lifecycle that includes several key stages:

  • The container starts when you run it from an image;
  • It remains running as long as its main process is active;
  • You can stop a running container with the docker stop command, which gracefully shuts down the container's process;
  • If you want to remove a container entirely, use docker rm, which deletes the container from your system.

Removing a container does not remove the underlying image, so you can always launch a new container from the same image later. Understanding these basic lifecycle commandsβ€”starting, stopping, and removing containersβ€”will help you manage your Docker environment efficiently as you build and test applications.

question mark

What does the docker run command do?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain more about the options available with the `docker run` command?

How do I know which ports to map when running a container?

What happens if I run multiple containers from the same image?

Awesome!

Completion rate improved to 7.14

bookRunning a Downloaded Image

Swipe to show menu

Launching Containers from Images

Launching containers from images is a fundamental part of working with Docker. To do this, you use the docker run command, which creates and starts a new container based on a specified image.

The general syntax for this command is:

docker run [OPTIONS] IMAGE [COMMAND]

Some of the most common options include:

  • -d: Runs the container in detached mode (in the background);
  • -p: Maps ports between your host and the container;
  • --name: Assigns a custom name to your container;
  • -it: Runs the container interactively, allowing you to use a shell inside the container.

Running the following command starts a new Ubuntu container and provides an interactive shell inside it:

docker run -p 8080:80 nginx

The -p flag maps the container’s internal port 80 to port 8080 on your local machine.

Once the container is running, you can open your browser and go to:

http://localhost:8080

You will see Nginx running at this address. Notice that nothing is running directly on your computerβ€”everything is running inside Docker.

Container Lifecycle: Starting, Stopping, and Removing Containers

Once a container has been started, it goes through a lifecycle that includes several key stages:

  • The container starts when you run it from an image;
  • It remains running as long as its main process is active;
  • You can stop a running container with the docker stop command, which gracefully shuts down the container's process;
  • If you want to remove a container entirely, use docker rm, which deletes the container from your system.

Removing a container does not remove the underlying image, so you can always launch a new container from the same image later. Understanding these basic lifecycle commandsβ€”starting, stopping, and removing containersβ€”will help you manage your Docker environment efficiently as you build and test applications.

question mark

What does the docker run command do?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2
some-alt