CFS Development Part 1: How to Set Up Core Flight System (cFS) in Docker on WSL
The Core Flight Software (cFS) framework has been a go to framework for developing scalable, reusable flight software. Its modular, plug-in architecture offers immense flexibility, making it ideal for systems that must adapt to changing requirements while maintaining 100% uptime. However, scaling this framework for large teams, complex projects, and evolving missions comes with its own unique challenges.
This blog series documents my journey to explore and demonstrate how to tackle those challenges effectively. My goal is to create a roadmap for large-scale cFS development, showcasing how to streamline workflows and enhance reliability of a system. Over the course of this series, I aim to share practical, step-by-step guides and conceptual insights that include:
Streamlined Development Environments: Simplifying setup with Docker and leveraging package management systems like Conan to manage dependencies for larger teams.
Fault-Tolerant System Design: Implementing redundancy and recovery mechanisms that are critical for mission success.
Simulation and Visualization: Integrating cFS with spacecraft simulation tools, including well-known visualization platforms like the Kerbal Space Program API, to simulate real-world scenarios.
Custom Applications: Developing mission-specific cFS applications while maintaining scalability and modularity.
Scalable Workflows: Using modern development tools like VS Code to make workflows efficient and collaborative for large teams.
Testing and Validation: Creating robust pipelines to ensure high reliability in environments where failure is not an option.
In this first post, I’ll start with the fundamentals: setting up cFS in a containerized environment using Windows Subsystem for Linux (WSL) and Docker. The goal is to establish a lightweight, portable, and consistent development environment that serves as the foundation for future work. From here, the series will evolve into more advanced topics, gradually building toward a fault-tolerant system and interactive simulations.
Overview
Goal: Set up and run cFS inside a Docker container on Ubuntu running in WSL.
Tools Used:
WSL 2 (Ubuntu)
Docker
Visual Studio Code (optional, but recommended)
Raspberry Pi (for future deployment)
Step 1: Install and Configure WSL
Install WSL and Ubuntu:
wsl --install
wsl --set-default-version 2
Verify WSL Installation:
wsl -l -v
Ensure Ubuntu is listed and running on version 2.
Install Ubuntu (if not already installed): Download it from the Microsoft Store.
Step 2: Install Docker on WSL
Install Docker Desktop:
Download from https://www.docker.com/products/docker-desktop/
Enable WSL 2 Integration for Ubuntu in Docker settings.
Install Docker in WSL:
sudo apt update
sudo apt install docker.io
sudo usermod -aG docker $USER
Restart WSL:
exit
wsl
Test Docker Installation:
docker --version
docker run hello-world
Step 3: Clone Core Flight Software (cFS)
Clone the cFS Repository:
git clone https://github.com/nasa/cFS.git
cd cFS
git submodule update --init --recursive
Copy in the default makefile and definitions:
cp cfe/cmake/Makefile.sample Makefile
cp -r cfe/cmake/sample_defs sample_defs
Step 4: Create a Dockerfile for cFS
Create a Dockerfile in the
cFS
Directory:
nano Dockerfile
Add the Following to the Dockerfile:
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=America/New_York
RUN ln -fs /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone && \
apt-get update && \
apt-get install -y build-essential cmake git tzdata && \
rm -rf /var/lib/apt/lists/*
WORKDIR /cfe
COPY . /cfe
Save and Exit (Ctrl + O, Enter, Ctrl + X).
Step 5: Build the Docker Container
This command is a check to ensure that docker is set up and ready for running in later steps when we compile and install.
Build the Docker Image:
docker build -t cfs-env .
Step 6: Increase Message Queue Limits (Fix OS QueueCreate Error)
Core Flight Software may fail to start due to insufficient message queue limits on the host system. This results in an error similar to:
OS_QueueCreate_Impl():119:OS_QueueCreate Error. errno = 22 (Invalid argument)
To fix this, increase the message queue limits:
Check Current Limits:
cat /proc/sys/fs/mqueue/msg_max
cat /proc/sys/fs/mqueue/msgsize_max
Temporarily Increase Limits:
sudo sysctl -w fs.mqueue.msg_max=256
sudo sysctl -w fs.mqueue.msgsize_max=65536
Persist the Changes (Optional):
sudo nano /etc/sysctl.conf
Add the following lines:
fs.mqueue.msg_max=256
fs.mqueue.msgsize_max=65536
Apply the changes:
sudo sysctl -p
Step 7: Prepare the Build Environment
Clean Previous Builds (Optional but Recommended):
docker run --rm -it -v $(pwd):/cfe -w /cfe cfs-env make distclean
Prepare for Compilation:
docker run --rm -it -v $(pwd):/cfe -w /cfe cfs-env make SIMULATION=native prep
Compile cFS:
docker run --rm -it -v $(pwd):/cfe -w /cfe cfs-env make
Install Compiled Binaries:
docker run --rm -it -v $(pwd):/cfe -w /cfe cfs-env make install
Step 8: Run Core Flight Software
Run cFS with Privileged Mode to Avoid Queue Errors:
sudo docker run --rm -it --privileged -v $(pwd):/cfe -w /cfe/build/exe/cpu1 cfs-env ./core-cpu1
--privileged
allows Docker to bypass security restrictions that prevent queue creation.
Check for Startup Messages:
Look for
CFE_ES_Main entering OPERATIONAL state
in the logs.If you see this message, cFS is successfully running!
Troubleshooting
Error:
cmake
not finding paths
Ensure you run
make SIMULATION=native prep
beforemake
.
Permissions Issue with Docker:
sudo chmod 666 /var/run/docker.sock
Timezone Prompt During Docker Build:
Use
DEBIAN_FRONTEND=noninteractive
in the Dockerfile to suppress interactive prompts.
Conclusion
You now have cFS running inside a Docker container on WSL! This environment serves as a foundation for future development, including deploying to Raspberry Pis for fault-tolerant flight computer systems.