概述
之前的文章我们介绍过如何将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很方便。
空空如常
求真得真