liveBook · Manning

Docker run

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

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

Use `docker run` to create and start a container from an image. It is a quick way to test a packaged microservice locally before publishing it, or to check that a published image can start. section 3.8.3 section 3.9.3

Start a local microservice

Run `docker run -d -p 3000:3000 -e PORT=3000 video-streaming`. The `-d` flag runs it in the background; omit it to see output in the terminal. `-p` forwards host port 3000 to container port 3000, while `-e` sets the service’s `PORT` environment variable. Docker prints a container ID. Use `docker container list` to find it later and `docker logs <container-id>` to inspect its output. Then test the service at `http://localhost:3000/video`. section 3.8.3

The image name can also identify an image in a remote registry. After publishing, run `docker run -d -p 3000:3000 -e PORT=3000 bmdk1.azurecr.io/video-streaming:latest` to test the published image on your development computer. To verify that Docker pulls it from the registry rather than using a cached local copy, first stop and remove containers created from the local image, then remove that image. Containers can otherwise keep running and consuming resources. section 3.9.3

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Explains a runnable command, port mapping, environment variables, detached mode, container IDs, logs, and the local-image cache.
Examples
Starts a video-streaming service on port 3000 and repeats the test with an Azure registry image.
What it assumes
Assumes an image has been built or published, while explaining the command flags needed to run it.
What you can do after
Operate/configure it to start a microservice, inspect its logs, and verify that a published image can be pulled and run.
How it connects
Connects Docker images, containers, environment variables, port forwarding, container registries, and Kubernetes deployment.

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 Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.