DOCKER - 8 While launching a container

In this lesson we look at what really happens behind the scenes when you run docker container run. Docker is often summarized as "the thing that runs containers", but a lot more goes on at launch time. From a single command, the engine fetches an image, prepares its layers, sets up the network and finally starts a process.

When you type docker container run ... nginx, the engine first looks for an image named nginx in the local image cache. If it does not find it, it falls back to Docker Hub, the default remote registry, downloads the image and stores it in the cache. Because we did not pin a version, the engine picks latest by default.

What Docker sets up next

  • No image copy: Docker does not duplicate the image. Instead it stacks a thin writable layer of changes on top of the image's read-only layers.
  • Virtual networking: the container is attached to a Docker virtual network and gets its own virtual IP address.
  • Port publishing: with --publish 80:80, the engine maps host port 80 to container port 80 and configures NAT accordingly. Without --publish, no host port is exposed.
  • Command execution: the container starts the default command specified in the image's Dockerfile (we will cover Dockerfiles in the next section).

A lot happens between the moment you press Enter and the moment your nginx welcome page is reachable on http://localhost. In later sections we will dive deeper into each of these areas: images and Dockerfiles, networks, volumes and orchestration. See you in the next video.

Summary

When you run `docker containers run`, Docker performs multiple background operations beyond simply starting a container. These include locating the specified image locally, pulling it from Docker Hub if necessary, creating a new container layer, configuring networking with virtual IP assignment, setting up port mapping, and finally executing the container's entry point command. Understanding these steps is essential for effective Docker usage and troubleshooting.

Key points

  • Docker searches for images locally first; if not found, it pulls from Docker Hub (default registry) and caches the latest version by default
  • A new container creates additional layers on top of the base image rather than copying the entire image
  • Virtual networking assigns each container a unique virtual IP address within Docker's internal network
  • Port mapping (e.g., 80:80) explicitly exposes container ports to the host; without port specification, no ports are accessible
  • The container executes the entry point command defined in the Dockerfile after all configuration is complete

FAQ

Where does Docker look for images when you run `docker containers run`?

Docker first searches for the image locally in its cache. If not found, it automatically pulls from Docker Hub (the default remote repository) and downloads the latest version unless a specific version tag is specified.

Does Docker copy the entire image into a new container?

No. Docker creates new change layers on top of the base image rather than copying it. This makes containers lightweight and efficient.

What happens with port mapping when launching a container?

Port mapping (specified in the run command) forwards traffic from a host port to a container port. For example, 80:80 maps host port 80 to container port 80. If no port mapping is specified, the container exposes no ports.