This guide covers building BeamSim using Docker and the included Makefile system.
- Docker with BuildKit support
- Git
- Make (optional, but recommended)
# Clone the repository
git clone https://github.com/qdrvm/beamsim.git
cd beamsim
# Build Docker image
make docker_image
# Test the build
make docker_test
# Run BeamSim
docker run --rm qdrvm/beamsim/beamsim:$(git rev-parse --short=7 HEAD)-amd64The build system uses the following configurable variables:
| Variable | Default | Description |
|---|---|---|
PLATFORM |
amd64 |
Target architecture (amd64, arm64) |
NS3_VERSION |
3.44 |
NS-3 network simulator version |
CLANG_VERSION |
19 |
Clang compiler version |
DOCKER_TAG |
$(GIT_COMMIT)-$(PLATFORM) |
Docker image tag |
DOCKER_REGISTRY |
qdrvm |
Docker registry prefix |
BeamSim uses a multi-stage Docker build:
- NS-3 Builder Stage: Downloads and compiles NS-3 network simulator
- BeamSim Builder Stage: Compiles the main BeamSim application using Clang
- Runtime Stage: Creates minimal production image with required libraries
- Primary Compiler: Clang (configurable version, default 19)
- C++ Standard: C++23
- Standard Library: libc++ (LLVM's implementation)
- Build Type: RelWithDebInfo (optimized with debug info)
Build Dependencies:
- Clang/LLVM toolchain
- CMake and Ninja
- NS-3 network simulator
- OpenMPI
- Various development libraries
Runtime Dependencies:
- libc++ and libc++abi
- OpenMPI runtime
- NS-3 libraries
- Standard system libraries
# Build with Clang 18
make docker_image CLANG_VERSION=18
# Build with Clang 20 (if available)
make docker_image CLANG_VERSION=20# Build for ARM64
make docker_image PLATFORM=arm64
# Build for both architectures (requires buildx)
make docker_buildx# Build with NS-3 version 3.43
make docker_image NS3_VERSION=3.43# Build with custom tag
make docker_image DOCKER_TAG=latest
# Build with version tag
make docker_image DOCKER_TAG=v1.0.0The build system is optimized for:
- Layer Caching: NS-3 is built in a separate stage for better cache utilization
- Parallel Compilation: Uses all available CPU cores (
ninja -j$(nproc)) - Minimal Runtime: Production image contains only essential dependencies
- Security: Runs as non-root user in production
- First Build: ~5-15 minutes (downloads and compiles NS-3)
- Incremental Builds: ~2-5 minutes (NS-3 cached, only BeamSim rebuilt)
- Code-only Changes: ~30-90 seconds (both NS-3 and dependencies cached)
Single platform build (works everywhere):
make docker_image
make docker_image PLATFORM=arm64Multi-platform build (requires setup):
# One-time setup
docker buildx create --name beamsim-builder --use
docker buildx inspect --bootstrap
# Build and push (uses default registry: qdrvm)
make docker_buildx
# Or use custom registry
make docker_buildx DOCKER_REGISTRY=your-custom-registry.com-
Missing BuildKit: Ensure Docker BuildKit is enabled
export DOCKER_BUILDKIT=1 -
Platform Issues: For ARM64 builds on x86_64, ensure qemu is installed
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
-
Multi-platform Build Issues: The
docker_buildxtarget requires proper buildx setup# Create and use a buildx builder docker buildx create --name beamsim-builder --use # Alternatively, enable containerd image store (Docker Desktop) # Settings > Features in development > Use containerd for pulling and storing images
-
Memory Issues: NS-3 compilation requires significant memory (4GB+ recommended)
-
Network Issues: Ensure access to apt.llvm.org and ns-3 download servers
# Build with verbose output
make docker_image DOCKER_BUILDKIT=0
# Check build logs
docker build --no-cache --progress=plain .
# Inspect intermediate stages
docker build --target ns3-builder -t debug-ns3 .
docker run -it debug-ns3 bashMulti-platform builds require Docker Buildx setup:
# Method 1: Create a dedicated buildx builder (recommended)
docker buildx create --name beamsim-builder --use
docker buildx inspect --bootstrap
# Method 2: Enable containerd image store (Docker Desktop)
# Go to Settings > Features in development > Use containerd for pulling and storing images
# Verify buildx is working
docker buildx lsOnce buildx is configured:
# Build for multiple platforms simultaneously
make docker_buildx
# Push to custom registry (if needed)
make docker_buildx DOCKER_REGISTRY=your-registry.com/beamsimFor more control over the build process, you can build each architecture separately and create a manifest:
# Build for each architecture
make docker_image PLATFORM=amd64 DOCKER_TAG=v1.0.0-amd64
make docker_push DOCKER_TAG=v1.0.0-amd64
make docker_image PLATFORM=arm64 DOCKER_TAG=v1.0.0-arm64
make docker_push DOCKER_TAG=v1.0.0-arm64
# Create multi-architecture manifest
make docker_manifest DOCKER_TAG=v1.0.0 DOCKER_REGISTRY=your-registry.comNote: Multi-platform builds automatically push to the registry (default: qdrvm). Make sure you're logged in:
docker login # For Docker Hub (default)
# or
docker login your-registry.com # For custom registry# Build and test in one command
make release
# Quick development iteration
make docker_image && make docker_test
# Check image size
make docker_sizeThe Makefile is designed for CI/CD integration:
# GitHub Actions example
- name: Build BeamSim
run: |
make docker_image DOCKER_TAG=${{ github.sha }}
make docker_test
make docker_push- See MAKEFILE.md for detailed Makefile command reference
- See DEPLOYMENT.md for deployment guidelines
- See main README.md for usage examples