OpenSIPs Dev Tips: setting up local docker compose environment with opensips, rtpengine, and mysql

·

2 min read

The docker compose file below will let you have a running opensips, rtpengine and mysql server.

Take note of the OPENSIPS_EXTRA_MODULES variable. Change that to include any extra modules you need in your opensips. Check out below the file for the other "extra" files you will need in your local directory/project to get this working.

version: "3.9"

networks:
  sip-net:
    driver: bridge
    ipam:
      config:
        - subnet: 172.40.0.0/16

services:
  db:
    image: mysql
    # NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
    # (this is just an example, not intended to be a production configuration)
    command: --default-authentication-plugin=mysql_native_password
    volumes:
      - db_data:/var/lib/mysql
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    restart: always
    stdin_open: true
    tty: true
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: opensips
      MYSQL_USER: opensips
      MYSQL_PASSWORD: opensipsrw

    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      timeout: 20s
      retries: 10
    networks:
      sip-net:
        ipv4_address: 172.40.0.10
  opensips:
    build:
      context: ./docker-opensips
      args:
        OPENSIPS_BUILD: releases
        OPENSIPS_VERSION: 3.3
        OPENSIPS_CLI: true
        OPENSIPS_EXTRA_MODULES: "opensips-mysql-module opensips-http-modules opensips-auth-modules"
    command: "/etc/sbin/opensips -FE"
    stdin_open: true
    tty: true
    volumes:
      - ./:/etc/opensips
    ports:
      - "6060:5060/udp"
    depends_on:
      db:
        condition: service_healthy
    networks:
      sip-net:
        ipv4_address: 172.40.0.11
  rtpengine:
    image: drachtio/rtpengine:latest
    command: rtpengine --interface private/172.40.0.12 --interface public/172.40.0.12!172.40.0.12 --listen-ng=172.40.0.12:22222
    networks:
      sip-net:
        ipv4_address: 172.40.0.12
volumes:
  db_data:

init.sql

You will need to give your opensips user from your opensips server access to the mysql database. Note this line in the compose.yaml above:

- ./init.sql:/docker-entrypoint-initdb.d/init.sql

This sql file will get run when it is started. Get more info here: https://hub.docker.com/_/mysql

GRANT ALL ON *.* TO 'opensips'@'%';

FLUSH PRIVILEGES;