on

Asterisk on Docker

main-image

Asterisk is an open source PBX system, created by Digium, more exactly, authored by Mark Spencer. Asterisk PBX allows people to make calls to each other but also connects them with telephone services, such as reaching the public network or VoIP services. Asterisk is certainly the number one PBX system out there.

Asterisk

Why combine Asterisk with Docker?

We can see many advantages in using Asterisk inside Docker, the main reason in my case was to solve my development environment. It allows us to spawn small Asterisk containers and test them with applications without needing to alter our own OS or use a heavy VM system. Docker is extremely fast and in a matter of seconds the container is running.

There is also a significant potential in deploying Asterisk for customers, for instance companies willing to provide small PBXs containers to their clients will find docker especially interesting.

This post is a simple recipe for how to create an Asterisk Docker. Right now, the only flaw is the port mapping, as we speak Docker doesn't have an elegant way to map range of ports to a container, this can be sorted with a long command line but it just won't be very pratical. This will certainly be sorted in the future, there is work in progress on the matter: https://github.com/jhorey/docker/pull/1

Before Docker 0.8 you might have encountered an issue in mapping UDP & TCP on the same port, this has now been solved in docker v0.8, so make sure you have 0.8 running at least.

Let's get our hands dirty and get started

Download Debian images:

$ docker pull debian

Run an image on a new container:

$ docker run -i -t debian:wheezy /bin/bash
$ Install Asterisk & Apache2
$ apt-get -y install apache2 asterisk

Configuration RTP Ports

Docker doesn't currently allow a range of ports to be opened, as such all RTP ports have to be specified on the command line. In the example above we are only opening 10, so you will be limited to 10 simulataneous calls.

Edit the Asterisk RTP configuration to ensure only these ports are used.

Edit /etc/asterisk/rtp.conf:

rtpstart=16384
rtpend=16394

Or:

$ sed -i "s/rtpstart=10000/rtpstart=16384/g" /etc/asterisk/rtp.conf
$ sed -i "s/rtpend=20000/rtpend=16394/g" /etc/asterisk/rtp.conf

Start and check that Asterisk is running

Start Asterisk:

$ /etc/init.d/asterisk start

Check that is well running and listening:

$ netstat -nap | grep asterisk

Quit and create and image

$ CTRL-P + CTRL-Q (this will return to your shell and keep the container running)

Retrieve the last Container ID:

$ `dl`
# dl is an alias -> alias dl='docker ps -l -q'

Commit your last container and create a new image:

$ docker commit -m "Asterisk with Apache" `dl` mydebian_apache_asterisk

Now, you can launch a new container and open ports for your container mydebianapacheasterisk:

$ docker run -d -p 9080:80 -p 5060:5060/tcp -p 5060:5060/udp -p 16384:16384/udp -p 16385:16385/udp -p 16386:16386/udp -p 16387:16387/udp -p 16388:16388/udp -p 16389:16389/udp -p 16390:16390/udp -p 16391:16391/udp -p 16392:16392/udp -p 16393:16393/udp -p 16394:16394/udp mydebian_apache_asterisk run

You can start as many containers as you want and stop them with docker stop. The command docker ps will allow you to watch all the running containers and the ports mapped to them.

I hope you found this post useful, feel free to drop some comments.

 
comments powered by Disqus