Defining A Dockerfile For The OCI Image¶
Overview¶
This guide defines best practices for creating Dockerfiles for RDK-B containerized applications.
Base Image Selection¶
Option 1: FROM scratch (Recommended for production)¶
| Pros | Cons |
|---|---|
| - Minimal size - No attack surface |
- Requires fully static binaries |
Option 2: FROM alpine (Minimal Linux base, much smaller than Debian)¶
| Pros | Cons |
|---|---|
| - Small (~5MB) - Includes package manager |
- Uses musl libc (not glibc) |
Static Linking with musl¶
To support scratch, compile binaries statically:
Rust Example¶
Install toolchain:
Minimal Runtime Dockerfile Example¶
FROM scratch
LABEL org.opencontainers.image.source="https://github.com/org/repo"
LABEL org.opencontainers.image.description="RDK-B OCI Application"
WORKDIR /app
COPY target/release/my-app /app/my-app
COPY templates /app/templates
COPY static /app/static
EXPOSE 8080
CMD ["/app/my-app"]
ENTRYPOINT vs CMD¶
CMD (Recommended)¶
- Default command
- Easily overridden
ENTRYPOINT (Optional)¶
- Harder to override
- Good for fixed-function containers
File Layout Best Practices¶
OCI Metadata Labels¶
Include standard labels in your Dockerfile:
LABEL org.opencontainers.image.version="1.2.3"
LABEL org.opencontainers.image.revision="abc1234"
LABEL org.opencontainers.image.source="https://github.com/org/repo"
LABEL org.opencontainers.image.description="RDK App"
Key Recommendations¶
- Prefer
FROM scratch+ static binaries - Use
alpineonly if dynamic dependencies are required - Keep images small (<50MB ideally)
- Avoid unnecessary tools (curl, bash, etc.)