Create a gist now

Instantly share code, notes, and snippets.

@jmyoung /Dockerfile
Last active Dec 13, 2015

Embed
What would you like to do?
Run Asterisk non-persistently in a Docker container
* Put config in /docker/asterisk/config
* Put g723 and g729 codecs in /docker/asterisk/codecs and list in systemd unit startup
* Create /docker/asterisk/logs dir for logs, /docker/asterisk/logs/cdr-csv for call records
* Set udpbindaddr and tcpbindaddr in sip.conf to your secondary IP
* Set rtpstart and rtpend in rtp.conf appropriately
* Add a second IP to your Docker host's main interfaces
* make build
* make install
* make start
* Rejoice!
[Unit]
Description=Asterisk Container
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/bin/docker run --rm=true --name asterisk -v /docker/asterisk/config:/etc/asterisk:ro -v /docker/asterisk/logs:/var/log/asterisk -v /docker/asterisk/codecs/codec_g723-ast18-gcc4-glibc-x86_64-pentium4.so:/usr/lib64/asterisk/modules/codec_g723-ast18-gcc4-glibc-x86_64-pentium4.so:ro -v /docker/asterisk/codecs/codec_g729-ast18-gcc4-glibc-x86_64-pentium4.so:/usr/lib64/asterisk/modules/codec_g729-ast18-gcc4-glibc-x86_64-pentium4.so:ro --net=host zencoffee/asterisk:latest
ExecStop=/usr/bin/docker stop -t 2 asterisk
[Install]
WantedBy=multi-user.target
FROM centos:6
MAINTAINER James Young <jyoung@zencoffee.org>
# Set up EPEL
RUN curl -L http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm -o /tmp/epel-release-6-8.noarch.rpm && \
rpm -ivh /tmp/epel-release-6-8.noarch.rpm && \
rm -f /tmp/epel-release-6-8.noarch.rpm
# Update and install asterisk
RUN yum update -y && yum install -y asterisk
# Set config as a volume
VOLUME /etc/asterisk
# And when the container is started, run asterisk
ENTRYPOINT [ "/usr/sbin/asterisk", "-f" ]
CONTAINER=asterisk
SHELLCMD=asterisk -rvvvvv
all: build install start
build:
docker build -t zencoffee/$(CONTAINER):latest .
install:
cp -f $(CONTAINER)_container.service /etc/systemd/system/$(CONTAINER)_container.service
systemctl enable /etc/systemd/system/$(CONTAINER)_container.service
firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 --proto udp -d 192.168.0.242 --dport 5060 -j ACCEPT
firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 --proto udp -d 192.168.0.242 --dport 10000:20000 -j ACCEPT
firewall-cmd --direct --add-rule ipv4 filter INPUT 0 --proto udp -d 192.168.0.242 --dport 5060 -j ACCEPT
firewall-cmd --direct --add-rule ipv4 filter INPUT 0 --proto udp -d 192.168.0.242 --dport 10000:20000 -j ACCEPT
start:
systemctl start $(CONTAINER)_container.service
sleep 2
systemctl status $(CONTAINER)_container.service
shell:
docker exec -it $(CONTAINER) $(SHELLCMD)
clean:
systemctl stop $(CONTAINER)_container.service || true
docker stop -t 2 $(CONTAINER) || true
docker rm $(CONTAINER) || true
docker rmi zencoffee/$(CONTAINER) || true
systemctl disable /etc/systemd/system/$(CONTAINER)_container.service || true
rm -f /etc/systemd/system/$(CONTAINER)_container.service || true
firewall-cmd --permanent --direct --remove-rule ipv4 filter INPUT 0 --proto udp -d 192.168.0.242 --dport 5060 -j ACCEPT || true
firewall-cmd --permanent --direct --remove-rule ipv4 filter INPUT 0 --proto udp -d 192.168.0.242 --dport 10000:20000 -j ACCEPT || true
firewall-cmd --direct --remove-rule ipv4 filter INPUT 0 --proto udp -d 192.168.0.242 --dport 5060 -j ACCEPT || true
firewall-cmd --direct --remove-rule ipv4 filter INPUT 0 --proto udp -d 192.168.0.242 --dport 10000:20000 -j ACCEPT || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment