
Recall first from L4T base images and device mapping
- An L4T image tag must be compatible with the Jetson Linux release running on the host
- The host kernel handles GPU requests through the device nodes made available to the container
- The image and NVIDIA runtime can supply different CUDA libraries
Choose and pull a Jetson base image
4 min readYou can run a container. This lesson answers how to build your own CUDA/TensorRT image and pull prebuilt ones from NGC.
An image can pull successfully and fail at the first inference request. Docker can confirm that it downloaded an ARM64 image while leaving the Jetson software compatibility question open. Start by identifying the Jetson release on the board and reading the requirements for the specific image tag. The Ubuntu 24.04 workstation can handle registry and Dockerfile work. The GPU test needs a supported Jetson installation. A Raspberry Pi or BeagleBone cannot substitute for the Jetson in that test.
uname -m
cat /etc/nv_tegra_release
Run these commands on the Jetson. The second command reads the installed L4T release information. Keep the release and revision with your build notes. In the NVIDIA NGC Catalog, look up the container repository, open the tags for it, and read the release notes for the candidate tag. Check the supported JetPack or L4T release and the versions of CUDA, TensorRT and any framework your application imports. Check for linux/arm64 in the published image information when available. A compatible CPU architecture is only one condition. A desktop CUDA container published for ARM64 can target a different NVIDIA platform.
NGC is NVIDIA's catalog and registry service. The catalog describes the images and supported releases. Docker pulls the image content from nvcr.io. The nvcr.io/nvidia/l4t-ml repository contains Jetson machine-learning images with a collection of frameworks and libraries that varies by tag. It is a candidate when an application imports those frameworks. The nvcr.io/nvidia/l4t-tensorrt repository is a candidate when the application mainly needs TensorRT. Read the contents of the exact tag before assuming it includes Python, trtexec, development headers or any other tool. If the named repositories offer no compatible tag for your board, use a TensorRT-capable image that NVIDIA documents for your Jetson release. Older tags remain tied to their documented release requirements.
Here, NGC_TAG is a shell variable you set to the published, compatible tag for the repository you choose. Tags for different repositories can have different names. This command uses the TensorRT repository.
base="nvcr.io/nvidia/l4t-tensorrt:${NGC_TAG:?Set the compatible NGC tag}"
docker pull --platform linux/arm64 "$base"
docker image inspect --format '{{.Os}}/{{.Architecture}} {{json .RepoDigests}}' "$base"
Use the same sequence with l4t-ml if that is your selection. If NGC requires credentials for the image, authenticate with docker login nvcr.io, using $oauthtoken as the literal username and your NGC API key as the password. Keep the key out of the Dockerfile. A tag selects a published image reference. A repository digest identifies specific content and can be recorded or used in FROM to keep later builds tied to that content. Verify the image architecture and keep the release notes alongside the digest, since the digest itself says nothing about Jetson compatibility.
You can run a prebuilt image directly when it already provides the program you need. Extending a prebuilt image lets you package a service with its source and defaults. If you build the user space yourself from a distribution base, you take responsibility for installing the compatible CUDA and TensorRT packages and their dependencies. Docker's literal FROM scratch starts with an empty filesystem. Using it for a dynamically linked application would require supplying the loader and every required user-space library yourself. For this lesson, use an existing compatible base.
Package a small TensorRT inference service
5 min readUse a small HTTP wrapper around TensorRT's trtexec for this lab. Each request starts trtexec with a saved engine and lets it generate its default input data. This demonstrates inference with a repeatable request. The endpoint does not accept input tensors or return model predictions. Use the saved engine from the earlier TensorRT lesson, generated for the target GPU and compatible TensorRT environment. Choose a fixed-shape model for these commands so the service does not need to supply input shapes. If the model uses custom TensorRT plugins, the image and invocation must also provide the required plugin libraries. The lab assumes an engine without custom plugins.
The base you selected must have python3 and trtexec on its executable search path. Use the paths documented for that tag. If the base ships trtexec outside PATH, add its directory with Dockerfile ENV PATH or set its absolute path in the wrapper and build check. If either program is absent, choose a compatible base that supplies it or add it using the supported package source for that image. The Dockerfile checks tool availability during the build. It leaves engine deserialization and inference for deployment on the board.
Save the following as service.py. The service exposes a fixed endpoint and uses a fixed engine path. It returns the exit status of the inference command in the response body and logs the command's diagnostic output to the container logs.
from http.server import BaseHTTPRequestHandler, HTTPServer
import subprocess
class Handler(BaseHTTPRequestHandler):
def do_POST(self):
if self.path != "/infer":
self.send_error(404)
return
try:
result = subprocess.run(
["trtexec", "--loadEngine=/models/model.plan",
"--warmUp=0", "--duration=0", "--iterations=1"],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
text=True, timeout=120, check=False,
)
except (OSError, subprocess.TimeoutExpired) as error:
self.log_error("%s", error)
self.send_error(500)
return
print(result.stdout, flush=True)
body = f"trtexec exit status: {result.returncode}\n".encode()
self.send_response(200 if result.returncode == 0 else 500)
self.send_header("Content-Type", "text/plain; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
HTTPServer(("0.0.0.0", 8080), Handler).serve_forever()
Write Dockerfile in the same directory. ARG lets you select the base at build time. COPY adds the service script from the build context. The JSON form of ENTRYPOINT asks Docker to execute Python directly. EXPOSE documents the service port. Publishing that port happens when you run the container.
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
RUN command -v python3 && command -v trtexec
WORKDIR /app
COPY service.py .
EXPOSE 8080
ENTRYPOINT ["python3", "-u", "/app/service.py"]
Build on the Jetson with the base variable set to the compatible image reference. The final . selects the current directory as the build context. Give the resulting image a local name and tag.
docker build --build-arg BASE_IMAGE="$base" -t jetson-infer:lab .
docker image inspect --format '{{.Size}}' jetson-infer:lab
docker image history jetson-infer:lab
Keep the context small by placing the Dockerfile and service script in a dedicated directory or excluding model files, build output and other local data with .dockerignore. This reduces the files Docker has to process. Image size depends on what actually enters the layers, including files inherited from the base. Use a base that supplies the libraries the application needs and copy only deployment files. If you install Debian packages, put apt-get update, apt-get install --no-install-recommends with your required packages, and cleanup of /var/lib/apt/lists/* in the same RUN instruction. Deleting files in a later instruction leaves the earlier layer containing those bytes. Compare the same docker image inspect size field across builds. That value describes the local image size and can differ from download size or additional disk space consumed when layers are shared.
Going deeperExplore the mechanism
Ship a compiled service without the toolchain
For a service written in C++ or CUDA, compile in a development stage with nvcc, CMake, a host compiler, and the required headers. Start the final stage from a compatible runtime image and copy the application artifacts explicitly. The example assumes your project already has CMake install rules that put the executable at bin/infer-server under the chosen install prefix. Supply the two base references with --build-arg and choose them together for the target architecture and supported CUDA and TensorRT stack.
ARG DEVEL_IMAGE
ARG RUNTIME_IMAGE
FROM ${DEVEL_IMAGE} AS build
WORKDIR /src
COPY . .
RUN cmake -S . -B /build -DCMAKE_BUILD_TYPE=Release \
&& cmake --build /build \
&& cmake --install /build --prefix /stage
FROM ${RUNTIME_IMAGE}
COPY --from=build /stage/bin/infer-server /usr/local/bin/infer-server
ENTRYPOINT ["/usr/local/bin/infer-server"]
Add explicit copies for application-owned shared libraries or plugins if the service uses them, and arrange for the application or dynamic loader to find them. The runtime base must provide compatible versions of the shared libraries used by the executable. A program can compile successfully and still fail if the target image lacks a library or exports an older symbol version. For your own trusted executable, ldd in the final environment can help identify missing linked dependencies. Exercise paths that load plugins at runtime too, since ldd only reports the executable's load-time dependency tree. See ld.so(8) for the loader's search rules.
The compile stage may remain in the local build cache. Its compiler and intermediate files enter the delivered image only if the final stage inherits them or copies them. Select a runtime base that actually omits the development toolchain. Compare the final image against the same application packaged on the development base, then run the same inference request in both images to check that the size reduction preserved functionality.
Deploy and verify on Jetson
3 min readPulling and building establish which files Docker has available. Deployment establishes whether the service can use those files with the target's NVIDIA runtime. Place the compatible engine at $PWD/model.plan on the board. The bind mount supplies that file at /models/model.plan and keeps it read-only. It also lets you update the engine independently of the service image. Use the NVIDIA runtime configured for this Jetson. The example publishes the lab service on the board's loopback interface.
docker run -d --name jetson-infer --runtime=nvidia \
-p 127.0.0.1:8080:8080 \
--mount "type=bind,src=$PWD/model.plan,dst=/models/model.plan,readonly" \
jetson-infer:lab
Inspect candidate GPU character devices on the host and inside the running service container. The filters cover common NVIDIA device naming conventions. Use the GPU nodes identified for your board if its release uses other names. Record the paths actually present.
find /dev -type c \( -name 'nvhost*' -o -name 'nvgpu*' -o -name 'nvidia*' \) -print
docker exec jetson-infer find /dev -type c \
\( -name 'nvhost*' -o -name 'nvgpu*' -o -name 'nvidia*' \) -print
Some names in those families can belong to other accelerators or to control interfaces. Match a node associated with your GPU against the host observation. To verify a specific node, set GPU_NODE to a confirmed path that appears in both environments. stat reports the file type and the major and minor device numbers. Those values depend on your board and installed software.
stat -c '%n %F %t:%T' "$GPU_NODE"
docker exec jetson-infer stat -c '%n %F %t:%T' "$GPU_NODE"
Then send an inference request from the board. Use docker logs to inspect the TensorRT diagnostics for that same request. If the request arrives before Python begins listening, retry after startup. A successful request requires trtexec to load the engine and complete its configured inference run.
curl --fail --show-error -X POST http://127.0.0.1:8080/infer
docker logs jetson-infer
If Docker cannot start the container, inspect the run error and verify that the selected runtime and mount are available. If the container starts but the expected nodes are absent, focus on the GPU runtime configuration. If the nodes are present and the request fails, read the TensorRT logs for the engine, library or CUDA error. A visible device node confirms the path exists in the container. The inference request checks whether the deployed software can use the device for the work it was packaged to do. When finished, use docker stop jetson-infer followed by docker rm jetson-infer to remove the lab container.
Container permissions and edge orchestration comes next. It asks how to run a verified image with the access it needs and manage its deployment on edge devices.
Key takeaways
- NGC image tags describe particular software releases, and ARM64 architecture alone does not establish Jetson compatibility.
- A Dockerfile can extend a compatible TensorRT base with only the files needed for deployment.
- A multi-stage build can leave headers, compilers, and build artifacts outside the final image.
- Visible GPU character devices and successful TensorRT inference provide separate evidence.
Reflect
- Explain to a colleague, in two sentences: select an NGC image using the target architecture, L4T release, and application dependencies.
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
Official documentation first. Links checked when the lesson was published.