liveBook · Manning

Docker run

As explained in Road to Kubernetes

docker run is a Docker command that creates and starts a container from a specified container image.

docker run creates and starts a container from an image. With docker run nginx, Docker pulls the image from Docker Hub when it is not available locally, then starts NGINX in the foreground. section 5.1.1

Add flags to connect the container to your machine and control how it runs:

  • Publish a port with -p localPort:containerPort, such as docker run -p 8080:80 nginx, then visit localhost:8080. section 5.1.2
  • Open an interactive shell with docker run -it nginx /bin/bash; inspect files with commands such as ls, then exit. section 5.1.3
  • Run in the background with -d, inspect running containers with docker ps, view logs with docker logs, and stop one with docker stop. section 7.1.4
  • Set a name with --name, remove an interactive container after use with --rm, or pass environment values with -e. section 5.2.2 section 5.4.2

Run NGINX locally and in the background

docker run -d --restart always --name my-nginx -p 80:80 nginx This starts NGINX from the nginx image, keeps it detached, publishes container port 80 on host port 80, assigns a predictable name, and configures automatic restart. section 7.1.4

Listing 5.1 Hello World with Docker: Running the NGINX container image
docker run nginx

See the minimal first-container command before adding ports, shells, names, and lifecycle flags. section 5.1.1

How Road to Kubernetes covers it

How deep it goes
Covers image pulling, port publishing, interactive shells, detached execution, environment variables, inspection, logs, and stopping.
Examples
Uses NGINX, Postgres, custom NGINX, Python, and Node.js images with mapped ports, shells, names, and environment variables.
What it assumes
Assumes Docker is installed and teaches container isolation, image execution, port mapping, and basic lifecycle control through NGINX.
What you can do after
Operate containers by pulling, launching, exposing, inspecting, entering, logging, stopping, and configuring them with command-line flags.
How it connects
Connects container images, Docker Hub, Dockerfiles, ports, environment variables, Docker Engine, and container process management.

Also explained in

Compare how 4 books explain docker run →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.