BIPS/Examples/Docker Containers: Difference between revisions

From RidgeRun Developer Wiki
(Created page with "Example")
 
No edit summary
Line 1: Line 1:
Example
<noinclude>
{{BIPS/Head|previous=|next=}}
</noinclude>
 
== 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:
 
<pre>
src
├── examples
   └── docker
       ├── bips.env
       ├── Dockerfile
       └── one-to-one.docker-compose.yml
</pre>
 
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 <code>docker-compose</code> file using <code>--env-file</code>
 
The options are:
 
<pre>
# 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
</pre>
 
== Running the examples ==
 
=== One-to-one example ===
 
In the root of the repo, execute:
 
<syntaxhighlight lang=bash>
COMPOSE_FILE=one-to-one.docker-compose.yml
docker-compose -f src/examples/docker/${COMPOSE_FILE} up --build
</syntaxhighlight>
 
It will create a couple of containers: one for the producer and another for the consumer.
 
=== One-to-many example ===
 
You can use the [https://docs.docker.com/compose/compose-file/deploy/#replicas replicas] property in Docker Compose. Please, modify <code>src/examples/docker/one-to-one.docker-compose.yml</code> as:
 
<syntaxhighlight lang=yaml>
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
</syntaxhighlight>
 
Save it as <code>src/examples/docker/one-to-many.docker-compose.yml</code>. This illustrates how you can introduce new replicas according to your needs. Afterwards, run
 
<syntaxhighlight lang=bash>
COMPOSE_FILE=one-to-many.docker-compose.yml
docker-compose -f src/examples/docker/${COMPOSE_FILE} up --build
</syntaxhighlight>
 
<noinclude>
{{BIPS/Foot||}}
</noinclude>

Revision as of 20:15, 14 December 2022



  Index  





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:

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



  Index