Normalized difference
Goal
Create a container and run the norm_diff step in the container image tagged localhost/norm-diff:latest.
Lab
This step has a dedicated lab at practice-labs/2-Containers/normalized-difference.ipynb.
Container
Each step has its own recipe to build the container image.
The norm_diff step container image recipe is:
| norm_diff/Dockerfile |
|---|
| FROM docker.io/library/python:3.12-slim@sha256:a6e34c598f2467ed0e9a8d349809fcd8b5c603269512df273a0bb1784edc11b1 AS builder
WORKDIR /src
COPY pyproject.toml README.md LICENSE.md ./
COPY src/ ./src/
RUN python -m pip wheel --no-cache-dir --no-deps --wheel-dir /dist .
FROM docker.io/library/python:3.12-slim@sha256:a6e34c598f2467ed0e9a8d349809fcd8b5c603269512df273a0bb1784edc11b1 AS runtime
RUN apt-get update && \
apt-get install -y --no-install-recommends libexpat1 && \
rm -rf /var/lib/apt/lists/* && \
groupadd --gid 2000 neo && \
useradd --uid 2000 --gid 2000 --create-home neo && \
python -m venv /app/venv && \
mkdir -p /work && chown 2000:2000 /work
ENV VIRTUAL_ENV=/app/venv
ENV PATH="/app/venv/bin:$PATH"
COPY --from=builder /dist/ /tmp/wheels/
RUN pip install --no-cache-dir /tmp/wheels/*.whl && \
norm_diff --help && \
rm -rf /tmp/wheels
USER 2000:2000
WORKDIR /work
ENTRYPOINT []
|
Build the container image with:
| terminal |
|---|
| export WORKSPACE=/workspace/mastering-app-package
podman build --format docker -t localhost/norm-diff:latest ${WORKSPACE}/water-bodies/command-line-tools/norm_diff
|
Run the container
The command to run the norm_diff step in the container is:
| podman \
run \
-i \
--userns=keep-id \
--mount=type=bind,source=/workspace/mastering-app-package/runs,target=/runs \
--mount=type=bind,source=/workspace/mastering-app-package/runs/crop_green.tif,target=/inputs/crop_green.tif,readonly \
--mount=type=bind,source=/workspace/mastering-app-package/runs/crop_nir.tif,target=/inputs/crop_nir.tif,readonly \
--workdir=/runs \
--read-only=true \
--user="$(id -u):$(id -g)" \
--rm \
--env=HOME=/runs \
localhost/norm-diff:latest \
norm_diff \
--rasters /inputs/crop_green.tif \
--rasters /inputs/crop_nir.tif
|
Step
Run the command to run the norm_diff step with:
sh -x ${WORKSPACE}/scripts/podman-norm-diff.sh
Expected outcome
The folder /workspace/mastering-app-package/runs contains:
(base) jovyan@coder-mrossi:~/runs$ tree .
.
├── crop_green.tif
├── crop_nir.tif
└── norm_diff.tif
0 directories, 3 files