1、环境准备
- Debian 10.*
- Docker (版本:19或者更高)
- opensips-3.2.3.tar.gz (https://opensips.org/pub/opensips/3.2.3/opensips-3.2.3.tar.gz)
2、编写Dockerfile文件
FROM debian:11.1
RUN apt-get update -y
# 编译安装opensips,所需要依赖环境
RUN apt-get install -y sngrep vim wget gcc bison flex make openssl unixodbc libxml2 libncurses5-dev gnupg2 less libsctp* libmysqlclient* zlib* libpq* libmicrohttpd* libjson-c-dev libmongoc-dev default-libmysqlclient-dev mariadb-server libhiredis* libxml2* libpcre*
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 049AD65B
RUN echo "deb https://apt.opensips.org bullseye cli-nightly" >/etc/apt/sources.list.d/opensips-cli.list
# 安装opensips-cli工具
RUN apt-get update -y && apt-get install -y opensips-cli
# 把opensips 3.2.3源码文件夹添加到镜像里,注意:opensips-3.2.3文件夹需要跟Dockerfile文件是同一层目录
RUN mkdir -p /tools/software/opensips-3.2.3
ADD ./opensips-3.2.3 /tools/software/opensips-3.2.3
# include_modules 选择需要的模块进行编译安装
RUN cd /tools/software/opensips-3.2.3 && make all include_modules="db_mysql db_postgres proto_tls proto_wss tls_mgm cachedb_mongodb cachedb_redis httpd json xcap presence presence_xml dialplan" prefix="/usr/local/opensips" install
# 添加 opensips.cfg 配置文件
RUN mkdir -p /usr/local/etc/opensips/
RUN cp /usr/local/opensips/etc/opensips/opensips.cfg /usr/local/etc/opensips/opensips.cfg
VOLUME ["/usr/local/opensips/etc"]
VOLUME ["/usr/local/etc/opensips/"]
EXPOSE 5060/udp
ENTRYPOINT ["/usr/local/opensips/sbin/opensips", "-FE"]
3、构建镜像
在Dockerfile目录下执行下面命令
docker build -t opensips-3.2.3 .
4、运行
宿主机目录:/data/opensips,需要提前准备opensips.cfg配置文件。
docker run --name opensips -it -v /data/opensips:/usr/local/opensips/etc/opensips -d opensips-3.2.3
5、利用opensips-cli初始化数据库结构
# 进入容器
docker exec -it opensips bash
# 新增.opensips-cli.cfg配置
vim ~/.opensips-cli.cfg
以下为.opensips-cli.cfg配置
[default]
log_level: WARNING
prompt_name: opensips-cli
prompt_intro: Welcome to OpenSIPS Command Line Interface!
prompt_emptyline_repeat_cmd: False
history_file: ~/.opensips-cli.history
history_file_size: 1000
output_type: pretty-print
communication_type: fifo
fifo_file: /tmp/opensips_fifo
# 选择模块添加数据库表结构
database_modules: ALL
# 数据库脚本目录
database_schema_path: /usr/local/opensips/share/opensips
# 数据库管理员账号
#database_admin_url: postgres://root@localhost
database_admin_url: mysql://root@localhost
# 会新建数据库账号:opensips,密码:opensipsrw
# database_url: postgres://opensips:opensipsrw@localhost
database_url: mysql://opensips:opensipsrw@localhost
# 数据库名称
database_name: opensips
保存.opensips-cli.cfg配置内容,后执行
opensips-cli -x database create
# 执行后需输入数据库管理员账号的密码
# 没有报错即可退出容器
exit