liveBook · Manning

Docker run

As explained in Data Pipelines with Apache Airflow, Second Edition

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

docker run creates and starts a container from an image, optionally passing arguments to the image's task. For example, an image can run a weather task for Amsterdam or display a CLI script's help output. section 11.2.4 section 11.4.2

Use docker run to:

  • Pass task arguments after the image name, such as a city name or a script command. section 11.2.4 section 11.4.2
  • Mount a host directory with --volume so the container can read or persist files outside its isolated filesystem. section 11.2.4
  • Remove the container automatically after completion with --rm, avoiding leftover stopped containers. section 11.2.4
  • Inspect, stop, or remove containers with docker ps, docker stop, and docker rm when cleanup is needed. section 11.2.4

Persisting weather output

Mount the local data directory at /data and write the container's output there: docker run --rm --volume `pwd`/data:/data manning-airflow/wttr-example Amsterdam --output_path /data/amsterdam.out. The resulting file appears as data/amsterdam.out on the host. section 11.2.4

Testing a task image

After building manning-airflow/movielens-fetch, run docker run --rm manning-airflow/movielens-fetch fetch-ratings --help to verify that the packaged CLI exposes its required options. section 11.4.2

Listing 11.8 Persisting output from the wttr container
$ docker run --rm --volume `pwd`/data:/data \
manning-airflow/wttr-example Amsterdam \
--output_path /data/amsterdam.out        #1

Use the complete volume-mounted command as a compact reference for passing task arguments, persisting output, and removing the finished container. section 11.2.4

How Data Pipelines with Apache Airflow, Second Edition covers it

How deep it goes
Explains image execution, argument passing, volume mounts, and container cleanup without detailing Docker internals.
Examples
Uses weather output persistence and MovieLens ratings CLI help as concrete execution examples.
What it assumes
Assumes a built container image and teaches storage mounts and lifecycle commands through concrete task runs.
What you can do after
Operate/configure Docker containers for task execution, file persistence, testing, and cleanup.
How it connects
Connects Docker images, containers, volumes, Dockerfiles, and command-line interfaces.

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 Data Pipelines with Apache Airflow, Second Edition. The section links point to the parts of the book it draws on.