Docker Deployment Tutorial
Deploying V2X FlexStack inside a Docker container ensures hermetic dependency isolation and simplifies distribution across edge and cloud testing infrastructure.
Example Dockerfile
FROM python:3.12-slim
WORKDIR /app
# Install build tools for native C-extension dependencies
RUN apt-get update && apt-get install -y \
gcc \
python3-dev \
build-essential \
iproute2 \
&& rm -rf /var/lib/apt/lists/*
# Install FlexStack
RUN pip install --no-cache-dir v2xflexstack==0.12.0
COPY app.py .
CMD ["python", "app.py"]
Example Node Application (app.py)
import argparse
import logging
import random
import time
from flexstack.btp.router import Router as BTPRouter
from flexstack.facilities.vru_awareness_service.vam_transmission_management import DeviceDataProvider
from flexstack.facilities.vru_awareness_service.vru_awareness_service import VRUAwarenessService
from flexstack.geonet.gn_address import GNAddress, M, ST, MID
from flexstack.geonet.mib import GnIfType, MIB
from flexstack.geonet.router import Router as GNRouter
from flexstack.linklayer.raw_link_layer import RawLinkLayer
from flexstack.utils.static_location_service import ThreadStaticLocationService
logging.basicConfig(level=logging.INFO)
def main() -> None:
parser = argparse.ArgumentParser(description="Run a C-ITS station in Docker")
parser.add_argument("--station-id", type=int, default=1)
parser.add_argument("--interface", type=str, default="eth0")
args = parser.parse_args()
mac_address = bytes([0x02] + [random.randint(0, 255) for _ in range(5)])
location_service = ThreadStaticLocationService(period=1000)
mib = MIB(
itsGnIfType=GnIfType.ITS_G5,
itsGnLocalGnAddr=GNAddress(m=M.GN_MULTICAST, st=ST.CYCLIST, mid=MID(mac_address)),
)
gn_router = GNRouter(mib=mib, sign_service=None)
location_service.add_callback(gn_router.refresh_ego_position_vector)
btp_router = BTPRouter(gn_router)
gn_router.register_indication_callback(btp_router.btp_data_indication)
vru_service = VRUAwarenessService(
btp_router=btp_router,
device_data_provider=DeviceDataProvider(station_id=args.station_id, station_type=2),
own_vru_profile="bicyclistAndLightVruVehicle",
)
location_service.add_callback(vru_service.vam_transmission_management.location_service_callback)
btp_router.freeze_callbacks()
link_layer = RawLinkLayer(args.interface, mac_address, receive_callback=gn_router.gn_data_indicate)
gn_router.link_layer = link_layer
print(f"C-ITS station {args.station_id} active on {args.interface}.")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
location_service.stop_event.set()
if __name__ == "__main__":
main()
Running the Container with Raw Socket Privileges
Because RawLinkLayer requires direct Layer-2 network frame injection, run the container with --net=host and the CAP_NET_RAW capability:
# Build image
docker build -t v2xflexstack-node .
# Run with host networking and net-raw capability
docker run --rm -it --net=host --cap-add=NET_RAW --cap-add=NET_ADMIN v2xflexstack-node