Skip to content
Thomas Mangin edited this page Oct 21, 2026 · 11 revisions

Docker Integration

Table of Contents

Overview

ExaBGP runs excellently in Docker containers, providing isolated, reproducible deployments. The official Docker image includes all necessary dependencies and follows container best practices.

Key Benefits:

  • Isolation: Separate BGP processes per container
  • Portability: Consistent deployment across environments
  • Scalability: Easy horizontal scaling with orchestration
  • Version Control: Pin specific ExaBGP versions
  • Resource Limits: Control CPU/memory per instance

ExaBGP does NOT manipulate the routing table (RIB/FIB) - it only speaks the BGP protocol. Route installation must be handled by external processes or network devices.

Official Docker Images

GitHub Container Registry

The images are published on the GitHub Container Registry, not on Docker Hub.

# The latest release, 5.0.13
docker pull ghcr.io/exa-networks/exabgp:5.0.13

# The same image, and whichever 5.0 release comes next
docker pull ghcr.io/exa-networks/exabgp:5.0

# The latest tag
docker pull ghcr.io/exa-networks/exabgp:latest

The 5.0 releases have their own tags. There is no image for 4.x or for the main branch; build one from the repository for those.

Image Details

  • Base: Python 3.13 slim-bookworm
  • Size: ~150MB
  • User: the container starts as root, and ExaBGP changes to the user exa (set as exabgp.daemon.user in the image's /opt/exabgp/etc/exabgp/exabgp.env) before starting its processes
  • Init: Uses dumb-init for proper signal handling
  • Dependencies: iproute2 included

Quick Start

Simple Announcement

Create a configuration file exabgp.conf:

neighbor 192.168.1.1 {
    router-id 10.0.0.1;
    local-address 10.0.0.2;
    local-as 65000;
    peer-as 65001;

    static {
        route 203.0.113.1/32 next-hop self;
    }
}

Run ExaBGP:

docker run -d \
    --name exabgp \
    --network host \
    -v $(pwd)/exabgp.conf:/etc/exabgp/exabgp.conf:ro \
    ghcr.io/exa-networks/exabgp:latest \
    /etc/exabgp/exabgp.conf

With Health Check

Configuration with ExaBGP's built-in health checker as API process:

process health-check {
    run exabgp healthcheck --cmd /usr/local/bin/health_check.py --ip 203.0.113.1/32 --no-ip-setup --withdraw-on-down;
    encoder json;
}

neighbor 192.168.1.1 {
    router-id 10.0.0.1;
    local-address 10.0.0.2;
    local-as 65000;
    peer-as 65001;

    api {
        processes [ health-check ];
    }
}

The health checker runs health_check.py every 5 seconds, and announces 203.0.113.1/32 once the script has exited with 0 three times in a row, withdrawing it after three failures. The script only checks the service, as in Application Health Integration. ExaBGP in the image starts its processes as the unprivileged user exa, so --no-ip-setup stops the checker from trying to add the address to the loopback. The Healthcheck page describes every option.

Run with health check script:

docker run -d \
    --name exabgp \
    --network host \
    -v $(pwd)/exabgp.conf:/etc/exabgp/exabgp.conf:ro \
    -v $(pwd)/health_check.py:/usr/local/bin/health_check.py:ro \
    ghcr.io/exa-networks/exabgp:latest \
    /etc/exabgp/exabgp.conf

Building Custom Images

Basic Dockerfile

FROM ghcr.io/exa-networks/exabgp:latest

# Add custom health check scripts
COPY health_checks/ /opt/exabgp/health_checks/
RUN chmod +x /opt/exabgp/health_checks/*.py

# Add custom configuration
COPY exabgp.conf /etc/exabgp/exabgp.conf

# Install additional dependencies
USER root
RUN apt-get update && \
    apt-get install -y curl netcat-openbsd && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

USER exa

ENTRYPOINT ["/usr/bin/dumb-init", "--", "exabgp"]
CMD ["/etc/exabgp/exabgp.conf"]

Build:

docker build -t myorg/exabgp-custom:1.0 .

Multi-Stage Build (From Source)

# syntax=docker/dockerfile:1.4
FROM python:3.13-bookworm AS builder

# Install uv for fast builds
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

WORKDIR /build

# Copy ExaBGP source
COPY . /build/

# Build wheel
RUN uv build --wheel

# Install to /opt/exabgp
RUN pip install --target /opt/exabgp dist/*.whl

# Production image
FROM python:3.13-slim-bookworm

COPY --from=builder /opt/exabgp /opt/exabgp

ENV PYTHONPATH=/opt/exabgp
ENV PATH=/opt/exabgp/bin:$PATH

# Install runtime dependencies
RUN apt-get update && \
    apt-get install -y iproute2 dumb-init curl && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Create ExaBGP user and directories
# (RUN uses /bin/sh, which does not expand exabgp.{in,out}: each name is written out)
RUN useradd -r -u 1000 exa && \
    mkdir -p /etc/exabgp /run/exabgp /var/log/exabgp && \
    mkfifo /run/exabgp/exabgp.in /run/exabgp/exabgp.out && \
    chown -R exa:exa /etc/exabgp /run/exabgp /var/log/exabgp && \
    chmod 600 /run/exabgp/exabgp.in /run/exabgp/exabgp.out

# Environment configuration: ExaBGP installed in /opt/exabgp reads
# /opt/exabgp/etc/exabgp/exabgp.env
RUN mkdir -p /opt/exabgp/etc/exabgp && \
    echo "[exabgp.daemon]" > /opt/exabgp/etc/exabgp/exabgp.env && \
    echo "user = 'exa'" >> /opt/exabgp/etc/exabgp/exabgp.env && \
    echo "[exabgp.log]" >> /opt/exabgp/etc/exabgp/exabgp.env && \
    echo "all = false" >> /opt/exabgp/etc/exabgp/exabgp.env && \
    echo "configuration = true" >> /opt/exabgp/etc/exabgp/exabgp.env

USER exa
WORKDIR /etc/exabgp

ENTRYPOINT ["/usr/bin/dumb-init", "--", "exabgp"]
CMD ["--help"]

Docker Compose Setup

Basic Setup

version: '3.8'

services:
  exabgp:
    image: ghcr.io/exa-networks/exabgp:latest
    container_name: exabgp
    network_mode: host
    restart: unless-stopped

    volumes:
      - ./config/exabgp.conf:/etc/exabgp/exabgp.conf:ro
      - ./scripts:/opt/scripts:ro
      - exabgp-logs:/var/log/exabgp

    environment:
      - exabgp_log_level=INFO
      - exabgp_api_ack=true

    command: /etc/exabgp/exabgp.conf

    healthcheck:
      test: ["CMD", "pgrep", "-f", "exabgp"]
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  exabgp-logs:

High Availability Setup (Multiple Nodes)

version: '3.8'

services:
  # ExaBGP Node 1
  exabgp-node1:
    image: ghcr.io/exa-networks/exabgp:latest
    hostname: exabgp-node1
    network_mode: host
    restart: unless-stopped

    volumes:
      - ./config/node1.conf:/etc/exabgp/exabgp.conf:ro
      - ./scripts/health_check.py:/opt/scripts/health_check.py:ro
      - node1-logs:/var/log/exabgp

    environment:
      - NODE_ID=1
      - SERVICE_IP=203.0.113.1
      - PRIMARY_METRIC=100

    command: /etc/exabgp/exabgp.conf

  # ExaBGP Node 2
  exabgp-node2:
    image: ghcr.io/exa-networks/exabgp:latest
    hostname: exabgp-node2
    network_mode: host
    restart: unless-stopped

    volumes:
      - ./config/node2.conf:/etc/exabgp/exabgp.conf:ro
      - ./scripts/health_check.py:/opt/scripts/health_check.py:ro
      - node2-logs:/var/log/exabgp

    environment:
      - NODE_ID=2
      - SERVICE_IP=203.0.113.1
      - PRIMARY_METRIC=101

    command: /etc/exabgp/exabgp.conf

  # Web service (example application)
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - ./html:/usr/share/nginx/html:ro
    depends_on:
      - exabgp-node1
      - exabgp-node2

volumes:
  node1-logs:
  node2-logs:

With Monitoring Stack

version: '3.8'

services:
  exabgp:
    image: ghcr.io/exa-networks/exabgp:latest
    network_mode: host
    restart: unless-stopped
    volumes:
      - ./config:/etc/exabgp:ro
      - ./scripts:/opt/scripts:ro
    command: /etc/exabgp/exabgp.conf
    labels:
      - "prometheus.scrape=true"
      - "prometheus.port=9576"

  # Prometheus exporter
  exabgp-exporter:
    image: lusis/exabgp_exporter:latest
    ports:
      - "9576:9576"
    # ExaBGP has no network API: an exporter has to receive ExaBGP's
    # messages as an ExaBGP process, see Prometheus Integration
    depends_on:
      - exabgp

  # Prometheus
  prometheus:
    image: prom/prometheus:latest
    ports:
      - "9090:9090"
    volumes:
      - ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus-data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'

  # Grafana
  grafana:
    image: grafana/grafana:latest
    ports:
      - "3000:3000"
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=admin
    volumes:
      - grafana-data:/var/lib/grafana
      - ./monitoring/dashboards:/etc/grafana/provisioning/dashboards:ro
    depends_on:
      - prometheus

volumes:
  prometheus-data:
  grafana-data:

Volume Management

Configuration Files

Mount configuration as read-only:

docker run -d \
    -v $(pwd)/exabgp.conf:/etc/exabgp/exabgp.conf:ro \
    ghcr.io/exa-networks/exabgp:latest

Scripts Directory

Mount scripts directory with execute permissions:

docker run -d \
    -v $(pwd)/scripts:/opt/scripts:ro \
    -v $(pwd)/exabgp.conf:/etc/exabgp/exabgp.conf:ro \
    ghcr.io/exa-networks/exabgp:latest

Ensure scripts are executable:

chmod +x scripts/*.py

Logs

ExaBGP writes its log on its standard error by default, which Docker keeps:

docker logs -f exabgp

To write it to a file instead, set exabgp_log_destination to a path the user exa can write to; ExaBGP opens the file after changing to that user.

Command Line Control

The image includes ExaBGP's command line client, which talks to the running ExaBGP:

# image 5.0.x
docker exec exabgp exabgp cli announce route 203.0.113.1/32 next-hop self

Multi-Container Patterns

Pattern 1: Sidecar Container

ExaBGP as sidecar to application:

services:
  app:
    image: myapp:latest
    network_mode: "service:exabgp"
    depends_on:
      - exabgp

  exabgp:
    image: ghcr.io/exa-networks/exabgp:latest
    hostname: app-bgp
    ports:
      - "179:179"  # BGP port
    volumes:
      - ./config/exabgp.conf:/etc/exabgp/exabgp.conf:ro
      - shared-scripts:/opt/scripts
    command: /etc/exabgp/exabgp.conf

volumes:
  shared-scripts:

Pattern 2: Shared Network Stack

Multiple containers sharing network:

services:
  exabgp:
    image: ghcr.io/exa-networks/exabgp:latest
    network_mode: host
    volumes:
      - ./exabgp.conf:/etc/exabgp/exabgp.conf:ro

  haproxy:
    image: haproxy:latest
    network_mode: host
    volumes:
      - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
    depends_on:
      - exabgp

Pattern 3: Service Discovery

services:
  exabgp:
    image: ghcr.io/exa-networks/exabgp:latest
    environment:
      - SERVICE_NAME=web
      - SERVICE_IP=203.0.113.1
      - CONSUL_ADDR=consul:8500
    volumes:
      - ./scripts/consul_discovery.py:/opt/scripts/discovery.py:ro
      - ./exabgp.conf:/etc/exabgp/exabgp.conf:ro

  consul:
    image: consul:latest
    ports:
      - "8500:8500"

Pattern 4: FlowSpec Controller

services:
  # FlowSpec controller
  # ExaBGP has no network API: the controller has to give its commands
  # to a process of ExaBGP, through a named pipe on a shared volume for
  # example (see the FastNetMon page)
  flowspec-controller:
    image: myorg/flowspec-controller:latest
    depends_on:
      - exabgp

  # ExaBGP FlowSpec announcer
  exabgp:
    image: ghcr.io/exa-networks/exabgp:latest
    network_mode: host
    volumes:
      - ./flowspec.conf:/etc/exabgp/exabgp.conf:ro
    command: /etc/exabgp/exabgp.conf

  # DDoS detection (example)
  fastnetmon:
    image: fastnetmon/fastnetmon:latest
    network_mode: host
    environment:
      - EXABGP_HOST=localhost
    depends_on:
      - exabgp

Kubernetes Deployment

See Kubernetes for comprehensive Kubernetes integration documentation.

Quick Example:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: exabgp
  namespace: bgp
spec:
  selector:
    matchLabels:
      app: exabgp
  template:
    metadata:
      labels:
        app: exabgp
    spec:
      hostNetwork: true
      containers:
      - name: exabgp
        image: ghcr.io/exa-networks/exabgp:latest
        args: ["/etc/exabgp/exabgp.conf"]
        volumeMounts:
        - name: config
          mountPath: /etc/exabgp
          readOnly: true
      volumes:
      - name: config
        configMap:
          name: exabgp-config

Health Checks

Docker Health Check

Add to Dockerfile or docker-compose.yml:

HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
  CMD pgrep -f exabgp || exit 1

BGP Session Check

More sophisticated health check:

#!/bin/bash
# health_check.sh

# Check if ExaBGP process is running
if ! pgrep -f "exabgp" > /dev/null; then
    echo "ExaBGP process not running"
    exit 1
fi

# Check if BGP session is established (requires netstat)
if ! netstat -tn | grep -q ":179.*ESTABLISHED"; then
    echo "No established BGP sessions"
    exit 1
fi

echo "ExaBGP healthy"
exit 0
healthcheck:
  test: ["/opt/scripts/health_check.sh"]
  interval: 30s
  timeout: 10s
  retries: 3
  start_period: 40s

Application Health Integration

Monitor application and announce via BGP. The script only checks the application and exits with 0 when it is healthy, and ExaBGP's health checker, given the script with --cmd as in With Health Check, announces or withdraws the route:

#!/usr/bin/env python3
# health_check.py

import sys
import urllib.request

def check_app_health():
    try:
        with urllib.request.urlopen('http://localhost:8080/health', timeout=2) as response:
            return response.status == 200
    except OSError:
        return False

sys.exit(0 if check_app_health() else 1)

The script uses the standard library only, because the image has no other Python package than ExaBGP.

When the decision needs logic the checker cannot express, Writing API Programs explains how to write your own program.

Networking

Host Network Mode

Recommended for BGP (needs direct access to network):

docker run -d --network host ghcr.io/exa-networks/exabgp:latest

Advantages:

  • Direct access to host network interfaces
  • BGP uses standard port 179
  • No NAT/port mapping complexity
  • Full routing table visibility

Considerations:

  • Less isolation
  • Containers share host network stack
  • Port conflicts possible

Bridge Network Mode

For development/testing only:

docker run -d \
    -p 179:179 \
    --network bridge \
    ghcr.io/exa-networks/exabgp:latest

Not recommended for production - BGP requires proper network access.

Custom Networks

# Create network
docker network create --driver bridge bgp-network

# Run ExaBGP
docker run -d \
    --network bgp-network \
    --name exabgp \
    ghcr.io/exa-networks/exabgp:latest

Macvlan (Advanced)

For multiple BGP speakers with unique IPs:

# Create macvlan network
docker network create -d macvlan \
    --subnet=192.168.1.0/24 \
    --gateway=192.168.1.1 \
    -o parent=eth0 \
    bgp-macvlan

# Run with unique IP
docker run -d \
    --network bgp-macvlan \
    --ip 192.168.1.10 \
    --name exabgp1 \
    ghcr.io/exa-networks/exabgp:latest

Troubleshooting

Container Won't Start

Check logs:

docker logs exabgp

Common issues:

  • Invalid configuration syntax
  • Missing configuration file
  • Port 179 already in use
  • Permission issues

BGP Session Not Establishing

Debug networking:

# Check if BGP port is accessible
docker exec exabgp netstat -tlnp | grep 179

# Test connectivity to peer
docker exec exabgp ping -c 3 192.168.1.1

# Check routing table (if host network)
docker exec exabgp ip route

# Verify BGP process
docker exec exabgp ps aux | grep exabgp

Configuration Errors

Validate configuration:

# Check configuration syntax (5.x image; ExaBGP 6.0 uses "configuration validate")
docker run --rm \
    -v $(pwd)/exabgp.conf:/etc/exabgp/exabgp.conf:ro \
    ghcr.io/exa-networks/exabgp:latest \
    validate /etc/exabgp/exabgp.conf

Script Not Executing

Check script permissions:

# Inside container
docker exec exabgp ls -la /opt/scripts/

# Should be executable (chmod +x)
chmod +x scripts/*.py

Logs Not Appearing

Enable verbose logging:

[exabgp.log]
all = true
destination = /var/log/exabgp/exabgp.log

Or use environment variable:

docker run -d \
    -e exabgp_log_level=DEBUG \
    ghcr.io/exa-networks/exabgp:latest

Performance Issues

Monitor resources:

# Container stats
docker stats exabgp

# Set resource limits
docker run -d \
    --memory="512m" \
    --cpus="1.0" \
    ghcr.io/exa-networks/exabgp:latest

Production Best Practices

1. Use Specific Version Tags

# Good
image: ghcr.io/exa-networks/exabgp:5.0.13

# Avoid
image: ghcr.io/exa-networks/exabgp:latest

2. Read-Only Root Filesystem

services:
  exabgp:
    image: ghcr.io/exa-networks/exabgp:5.0.13
    read_only: true
    tmpfs:
      - /tmp
      - /run

3. Resource Limits

services:
  exabgp:
    image: ghcr.io/exa-networks/exabgp:5.0.13
    deploy:
      resources:
        limits:
          cpus: '1.0'
          memory: 512M
        reservations:
          cpus: '0.5'
          memory: 256M

4. Restart Policy

services:
  exabgp:
    image: ghcr.io/exa-networks/exabgp:5.0.13
    restart: unless-stopped

5. Logging Configuration

services:
  exabgp:
    image: ghcr.io/exa-networks/exabgp:5.0.13
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

6. Security Hardening

services:
  exabgp:
    image: ghcr.io/exa-networks/exabgp:5.0.13
    security_opt:
      - no-new-privileges:true
    cap_drop:
      - ALL
    cap_add:
      - NET_ADMIN  # Only if needed
      - NET_RAW

7. Configuration as Code

# Store configs in git
git/
├── docker-compose.yml
├── config/
│   ├── exabgp.conf
│   └── exabgp.env
└── scripts/
    ├── health_check.py
    └── announce.py

8. Automated Testing

services:
  exabgp-test:
    image: ghcr.io/exa-networks/exabgp:5.0.13
    profiles: ["test"]
    command: validate /etc/exabgp/exabgp.conf    # 5.x image
    volumes:
      - ./config:/etc/exabgp:ro

Run tests:

docker compose --profile test up exabgp-test

9. Monitoring

ExaBGP serves no metrics itself: these labels describe the exporter process ExaBGP runs in the container, see Prometheus Integration:

services:
  exabgp:
    image: ghcr.io/exa-networks/exabgp:5.0.13
    labels:
      - "prometheus.scrape=true"
      - "prometheus.port=9576"
      - "prometheus.path=/metrics"

10. Backup Configuration

# Backup script
#!/bin/bash
docker exec exabgp cat /etc/exabgp/exabgp.conf > backup/exabgp.conf.$(date +%Y%m%d)

Complete Production Example

Full production-ready docker-compose.yml:

version: '3.8'

services:
  exabgp:
    image: ghcr.io/exa-networks/exabgp:5.0.13
    container_name: exabgp-prod
    hostname: bgp-node1
    network_mode: host
    restart: unless-stopped

    volumes:
      - ./config/exabgp.conf:/etc/exabgp/exabgp.conf:ro
      - ./config/exabgp.env:/etc/exabgp/exabgp.env:ro    # read with --env-file, see command
      - ./scripts:/opt/scripts:ro
      - exabgp-logs:/var/log/exabgp

    environment:
      - NODE_ID=1
      - CLUSTER=production
      - REGION=us-east-1

    healthcheck:
      test: ["CMD", "/opt/scripts/health_check.sh"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "5"
        labels: "service=exabgp"

    security_opt:
      - no-new-privileges:true

    deploy:
      resources:
        limits:
          cpus: '2.0'
          memory: 1G
        reservations:
          cpus: '0.5'
          memory: 256M

    labels:
      - "com.example.service=exabgp"
      - "com.example.environment=production"
      - "prometheus.scrape=true"
      - "prometheus.port=9576"

    command: --env-file /etc/exabgp/exabgp.env /etc/exabgp/exabgp.conf

volumes:
  exabgp-logs:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /var/log/exabgp

See Also

References


Clone this wiki locally