docker build constructs a Docker image from a Dockerfile and a build context. Docker reads the Dockerfile, finds referenced files such as scripts and dependency manifests, executes its instructions, and assigns the resulting image a tag. section 11.2.3
A typical image-building workflow is:
- Create a Dockerfile beginning with a base image, then add dependencies, application files, environment settings, and startup instructions. section 11.2.3
- Place the Dockerfile and files referenced by COPY or ADD in the build context, commonly the current directory. section 11.2.3
- Build and tag the image with a command such as docker build --tag manning-airflow/wttr-example . section 11.2.3
- Test the result with docker run, checking that the packaged command responds as expected. section 11.2.3
Packaging a task image
For a task that fetches movie ratings, first turn the Python logic into a command-line script, declare dependencies such as click and requests, copy the script into a Python base image, and build it with docker build -t manning-airflow/movielens-fetch .. Running docker run --rm manning-airflow/movielens-fetch fetch-ratings --help verifies the available options before using the image with DockerOperator. section 11.4.2
Listing 11.3 Dockerfile for fetching weather from the wttr.in API
FROM python:3.12-slim #1 COPY requirements.txt /tmp/requirements.txt #2 RUN pip install -r /tmp/requirements.txt COPY scripts/fetch_weather.py /usr/local/bin/fetch-weather #3 RUN chmod +x /usr/local/bin/fetch-weather ENTRYPOINT [ "/usr/local/bin/fetch-weather" ] #4 CMD [ "--help" ] #5
Inspect a complete Dockerfile showing a Python base image, dependency installation, script copying, executable permissions, ENTRYPOINT, and default arguments. section 11.2.3



