Skip to main content

Building Images

HYPR builds images from Dockerfiles using an isolated build process.

Basic Build

This parses the Dockerfile, executes each instruction, and produces a squashfs image.

Build Process

  1. Parse Dockerfile - Validate syntax, extract stages and instructions
  2. Resolve Base Image - Pull base image from registry if not cached
  3. Execute Instructions - Run each instruction in an isolated build VM
  4. Create Layers - Cache each layer for incremental builds
  5. Generate Squashfs - Compress final rootfs to squashfs format
  6. Store Manifest - Save image metadata (entrypoint, env, ports, etc.)

Supported Instructions

FROM

Set base image for the build stage.

RUN

Execute commands during build.

COPY

Copy files from build context or previous stage.

ADD

Copy files with automatic extraction.

ENV

Set environment variables.

ARG

Define build-time variables.
Pass values at build time:

WORKDIR

Set working directory.

USER

Set the user for subsequent instructions and runtime.

EXPOSE

Document exposed ports.

ENTRYPOINT

Set the executable.

CMD

Set default arguments.

VOLUME

Declare mount points.

LABEL

Add metadata.

HEALTHCHECK

Define health check command.

SHELL

Set default shell.

STOPSIGNAL

Set stop signal.

Multi-Stage Builds

Use multiple FROM instructions to create smaller final images.
Build specific stage:

Build Arguments

Define with ARG in Dockerfile:
Pass at build time:

Build Cache

HYPR caches layers based on instruction content. Cache is invalidated when:
  • Dockerfile instruction changes
  • Files copied by COPY/ADD change
  • Base image changes
  • Build argument values change
Disable cache:
Clear all cached layers:

Image Storage

Built images are stored in /var/lib/hypr/images/ as squashfs files with accompanying manifest JSON. List images:

Example Dockerfiles

Node.js Application

Go Application

Python Application

Managing Images

List local images:
Remove an image:
Force remove:
Inspect image:
Remove unused images:

Compose Builds

Build images as part of stack deployment:
Deploy with build:

Limitations

No Network During Build

Build VMs have no network access for security. All dependencies must be:
  • Included in the base image
  • Added to the build context
  • Downloaded in a previous multi-stage build

Platform-Specific

Images are built for the current platform (x86_64 or ARM64). Cross-platform builds are not supported.

Not BuildKit

HYPR uses its own build implementation. Some advanced BuildKit features are not supported:
  • Secret mounts (--mount=type=secret)
  • SSH mounts (--mount=type=ssh)
  • Cache mounts (--mount=type=cache)
  • Git context URLs

Best Practices

  1. Use multi-stage builds to minimize image size
  2. Order instructions by change frequency (stable first)
  3. Combine RUN commands to reduce layers
  4. Use .dockerignore to exclude unnecessary files
  5. Set USER to avoid running as root
  6. Define HEALTHCHECK for container health monitoring
  7. Use specific tags instead of latest for reproducibility

Troubleshooting

Build Fails

  1. Check Dockerfile syntax
  2. View build output for error messages
  3. Verify base image is available
  4. Ensure context files exist

Out of Space

Cache Not Working

Cache is invalidated when instruction or context files change. Use --no-cache to force rebuild.