使用docker-compose管理freeswitch容器

求真得真發表於2024-03-16

概述

之前的文章我們介紹過如何將freeswitch做成docker映象,也使用命令列模式正常啟動了fs的docker容器。

但是當我們需要同時管理多個docker容器的時候,還是使用docker-compose更簡單。

環境

CENTOS 7

docker engine:Version 25.0.3

Docker Compose version v2.24.6

centos docker:7

freeswitch:v1.6.20

docker-compose安裝

使用docker-ce的yum源安裝。

sudo yum remove docker \

docker-client \

docker-client-latest \

docker-common \

docker-latest \

docker-latest-logrotate \

docker-logrotate \

docker-selinux \

docker-engine-selinux \

docker-engine

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

sudo yum makecache fast

sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

ll /usr/libexec/docker/cli-plugins/docker-compose

sudo ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/bin/docker-compose

sudo ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/local/bin/docker-compose

docker-compose version

Docker Compose version v2.24.6

docker-compose.yml

docker-compose使用yaml配置檔案來管理docker容器,配置好yaml檔案之後就可以很方便的使用了。

cat docker-compose.yml

version: '2'

services:

freeswitch:

image: 10.55.55.136:5000/zr/centos.7-fs.1.6.19-release:v1.8.1

container_name: centos.7-fs.1.6.19-1.8.1-as

volumes:

- /usr/local/freeswitch/conf-as:/usr/local/freeswitch/conf

- /usr/local/freeswitch/log:/usr/local/freeswitch/log

- /data/RAS/recordings:/data/RAS/recordings

- /usr/local/freeswitch/sounds:/usr/local/freeswitch/sounds

- /usr/local/freeswitch/webapp:/usr/local/freeswitch/webapp

# command:

restart: unless-stopped

# privileged: true

network_mode: "host"

logging:

driver: "none"

ulimits:

nproc: 65535

nofile:

soft: 20000

hard: 40000

cb:

image: 10.55.55.136:5000/zr/centos.7-cb.1.6.19-release:v1.1.3

container_name: centos.7-cb.1.6.19-1.1.3-compose

volumes:

- /usr/local/CB/CB.cfg:/usr/local/CB/CB.cfg

- /usr/local/CB/logs:/usr/local/CB/logs

- /data/RAS/recordings:/data/RAS/recordings

- /usr/local/freeswitch/sounds:/usr/local/freeswitch/sounds

- /usr/local/freeswitch/webapp:/usr/local/freeswitch/webapp

# command:

restart: unless-stopped

# privileged: true

network_mode: "host"

logging:

driver: "none"

depends_on:

- freeswitch

profiles:

- cb

# sudo docker-compose --profile cb up -d

簡單介紹一下配置檔案。

啟動兩個docker容器,freeswitch和cb,cb為可選,使用“cb”profile啟動。

測試

使用上面的yml檔案啟動容器。

$ sudo docker-compose --profile cb up -d

[+] Running 2/2

✔ Container centos.7-fs.1.6.19-1.8.1-as Started 0.0s

✔ Container centos.7-cb.1.6.19-1.1.3-compose Started

$ sudo docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

592f8bdfc962 10.55.55.136:5000/zr/centos.7-cb.1.6.19-release:v1.1.3 "/usr/local/CB/CB-do…" 7 days ago Up 49 seconds centos.7-cb.1.6.19-1.1.3-compose

82fdee3f4717 10.55.55.136:5000/zr/centos.7-fs.1.6.19-release:v1.8.1 "/bin/sh -c '/usr/lo…" 7 days ago Up 50 seconds centos.7-fs.1.6.19-1.8.1-as

總結

docker-compose簡化了多個docker容器的管理難度。

對於docker叢集的部署,使用docker-compose很方便。

空空如常

求真得真

相關文章