Notice that we’ve set up the argument, ARG ROS_DISTRO=humble, so it can be changed for other distributions of ROS 2 (Iron, Rolling, etc.). Rather than creating multiple Dockerfiles for different configurations, you should try using build arguments like these as much as possible
To build your image with a specific argument — let’s say you want to use ROS 2 Rolling instead — you could do the following… provided that all your references to ${ROS_DISTRO} actually have something that correctly resolves to the rolling distribution.
In Docker, TARGETARCH is a built-in build argument that represents the target architecture (e.g., linux/amd64, linux/arm64, etc.) for the image you are building. This is particularly useful when building multi-architecture images using Docker’s Buildx feature. Example:
# syntax=docker/dockerfile:1FROM --platform=$BUILDPLATFORM alpine:latestARG TARGETARCHRUN echo "Building for architecture: $TARGETARCH"# Copy binary depending on the target architectureCOPY --from=builder /binaries/$TARGETARCH/mybinary /usr/local/bin/mybinary
• Multi-architecture builds: To build images for multiple architectures simultaneously, use the docker buildx build command with the —platform flag. This will automatically set the TARGETARCH argument for each build.
Create a builder image as building multi-platform images is currently only supported when using BuildKit with docker-container and kubernetes driversbash