Buffer Interprocess Sharing: Examples - Docker Containers
Buffer Interprocess Sharing | |
---|---|
![]() | |
BIPS Basics | |
|
|
Getting Started | |
|
|
User Manual | |
|
|
Examples | |
|
|
Performance | |
|
|
Contact Us | |
|
Introduction
The Docker examples take into account two possible cases:
- One-to-one communication
Within the source code, there are Dockerfiles, and Docker Compose files that illustrate how BIPS is capable of running on containers. Please, consider the following file tree:
src ├── examples └── docker ├── bips.env ├── Dockerfile └── one-to-one.docker-compose.yml
Make sure to have docker and docker-compose installed in your system. You can follow these guides:
- [Docker](https://docs.docker.com/engine/install/ubuntu/)
- [Docker Compose](https://docs.docker.com/compose/install/linux/#install-using-the-repository)
Example options
The Docker Compose file is parametric through environment variables. You can modify the parameters of the execution in the:
- bips.env
or provide an environment file through the docker-compose
file using --env-file
The options are:
# Buffer pool size in buffers BUFFER_POOL_SIZE=10 # Channel name - how the containers are communicated. You can leave it like that CHANNEL=/docker_test # Buffer size to transmit (4K image in RGBA) BUFFER_SIZE=33177600 # Number of data to process (minimum 8 bytes, maximum buffer size). It increases the processing time. PROCESS_SIZE=64 # Timeout in case of interruption (in seconds) TIMEOUT=15 # Number of transmissions NUM_ITERATIONS=1000
Running the examples
One-to-one example
In the root of the repo, execute:
COMPOSE_FILE=one-to-one.docker-compose.yml
docker-compose -f src/examples/docker/${COMPOSE_FILE} up --build
It will create a couple of containers: one for the producer and another for the consumer.
One-to-many example
You can use the replicas property in Docker Compose. Please, modify src/examples/docker/one-to-one.docker-compose.yml
as:
version: "3.9"
services:
# Producer service example: build an image compiling the examples
# and raising the producer example
producer:
build:
# The docker compose command must be invoked in the root directory
# to get the source code
dockerfile: src/examples/docker/Dockerfile
context: ../../..
env_file:
- ./bips.env
environment:
# Application to launch
- APP=producer
volumes:
# The shared memory must be shared
- /dev/shm:/dev/shm:rw
# Consumer service example: build an image compiling the examples
# and raising the consumer example
consumer:
build:
# The docker compose command must be invoked in the root directory
# to get the source code
dockerfile: src/examples/docker/Dockerfile
context: ../../..
deploy:
mode: replicated
replicas: 2
env_file:
- ./bips.env
environment:
# Application to launch
- APP=consumer
volumes:
# The shared memory must be shared
- /dev/shm:/dev/shm:rw
depends_on:
# The consumer cannot start without a producer
producer:
condition: service_started
Save it as src/examples/docker/one-to-many.docker-compose.yml
. This illustrates how you can introduce new replicas according to your needs. Afterwards, run
COMPOSE_FILE=one-to-many.docker-compose.yml
docker-compose -f src/examples/docker/${COMPOSE_FILE} up --build