This document describes the Docker-based environment used in Kafnus, including the docker-compose files, build configuration for custom images, and helper scripts.
Most of Docker-related files are located in the docker/ directory:
docker/
├── docker-compose.kafka.yml
├── docker-compose.ngsi.yml
├── docker-compose.orion.yml
├── docker-compose.postgis.yml # (optional, disabled by default)
├── docker-compose.monitoring.yml # (optional, disabled by default)
├── docker-up.sh
└── docker-down.sh
Custom Dockerfiles are located in their respective component repositories:
kafnus-ngsi/
└── Dockerfile # builds Kafnus NGSI (Node.js stream processor)
Kafnus Connect (persistence layer) is maintained in a separate repository: kafnus-connect
Starts the default stack, including:
- Kafka + Kafnus Connect
- Kafnus NGSI
- Orion + Mongo
PostGIS and Monitoring are commented out by default.
./docker-up.shYou can pass arguments like
-dto run in detached mode.
Stops the same services and removes volumes & orphan containers:
./docker-down.shThe Docker Compose setup relies on two custom images:
- Kafnus Connect → built from kafnus-connect, based on Kafka 4.1.0 + OpenJDK 17.
Includes all plugins: JDBC (PostGIS), MongoDB, HTTP, and custom SMTs. - Kafnus NGSI → built from this repository (
kafnus-ngsi/Dockerfile), containing the Node.js-based stream processing logic.
Both images are downloaded automatically by docker-up.sh, so manual builds are rarely needed.
Defines:
-
Kafka broker (port 9092, 29092)
-
Kafnus Connect image with plugins:
- Builds and runs custom image
- Custom plugins in
${CONNECT_PLUGIN_PATH}(default/usr/local/share/kafnus-connect/plugins) - Monitoring enabled via JMX Exporter (path
/home/appuser/jmx_exporter)
-
Connect waits for Kafka to be healthy before starting
-
For tests, environment variables for sink connectors are defined (
KAFNUS_TESTS_PG_HOST,KAFNUS_TESTS_PG_PORT...)
Topics are auto-created (KAFKA_AUTO_CREATE_TOPICS_ENABLE=true)
To build the Kafnus Connect image manually, follow the guide in the kafnus-connect repository.
Defines:
create-topics: Unused. Creates all source Kafka topics needed by Kafnus NGSIkafnus-ngsi: Builds and runs the Faust service
Note: The
create-topicsservice is no longer required and its lines are commented out in the Docker file.
If needed, this service could be repurposed to define the number of partitions for the input Kafka topics.
Kafnus NGSI image is built from the Dockerfile.
Exposes:
- Port
8000: Prometheus metrics - Port
6066: Optional Faust web interface (disabled by default)
To build from /kafnus-ngsi directory you can use:
docker build --no-cache -t kafnus-ngsi .Defines:
- Orion Context Broker
- MongoDB
- Mosquitto
Orion is configured to use Mosquitto as MQTT broker and MongoDB as DB backend. The broker reads config via command: -dbURI.
Defines the PostGIS database container:
-
Image: Defined via the
KAFNUS_POSTGIS_IMAGEenvironment variable.
By default, it uses the public imagepostgis/postgis:15-3.3, but internal environments may override this withtelefonicaiot/iotp-postgis. -
Volume: Mounts
${KAFNUS_DBPATH_POSTGIS}as the data directory.
IMPORTANT: This directory must exist and be owned by UID 999 and GID 999 (commonly used by PostGIS), or the container will fail to start.
Example:sudo chown -R 999:999 ${KAFNUS_DBPATH_POSTGIS} -
Ports: Exposes port
5432for database access.
You can activate this container by uncommenting the relevant line in docker-up.sh.
Includes:
- Prometheus
- Grafana
- Kafka Exporter
Disabled by default. You can enable it by uncommenting in docker-up.sh.
All services connect to the external Docker network:
networks:
kafka-postgis-net:
external: trueMake sure this network exists (e.g. using docker network ls) otherwise create it using:
docker network create kafka-postgis-netKafnus Connect automatically bundles required connectors and SMTs at image build time (see kafnus-connect/Dockerfile).
Plugin directory (${CONNECT_PLUGIN_PATH}) includes:
header-router→ custom SMT for routing based on message headerskafka-connect-jdbc→ custom JDBC connector (PostGIS support)mongodb→ MongoDB sink connectorhttp→ HTTP sink connector for pushing data to external APIs
End-to-end tests use Testcontainers to dynamically spin up Kafka, Kafnus NGSI, and Kafnus Connect environments.
Connector definitions used in tests are stored under:
tests_end2end/sinks/
Refer to the 08_testing.md guide for full details.