Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Running a Downloaded Image | Section
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

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 6

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

bookRunning a Downloaded Image

Scorri per mostrare il 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

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 6
some-alt