Asterisk in Docker: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
mNo edit summary
Line 1: Line 1:
Read the [[Docker]] page if you don't know what Docker is.
Read the [[Docker]] page if you don't know what Docker is.


Notes on building a current executable, the old way: [[Building Asterisk]]
Notes on building Asterisk executables from source, the old way: [[Building Asterisk]]. All this is built into my build-asterisk image and automated now.


== Building a docker container ==
Read the [[Twilio]] and [[Asterisk debugging]] pages too.


I started with the github respoke/asterisk image as my starting point. Then I did my own version because I wanted to use the latest Asterisk and respoke does not appear to get updated.
== Building a configured Asterisk Docker container ==


Then I broke respoke's image out into two parts, so that it would build faster.
I started with the github respoke/asterisk image as my starting point. Then I did my own version (brian32768/docker-build-asterisk in github or wildsong/asterisk in hub.docker.com) because I wanted to use the latest Asterisk and respoke does not appear to get updated.


I have a container on hub.docker.com called wildsong/build-asterisk that has all the
On Bellman I keep the sources checked out here: source/docker/docker-build-asterisk
tools in it, when the container builds it downloads sources and
configures and compiles them. I keep the source here on Bellman.


cd source/docker/docker-build-asterisk
Once the 'build-asterisk' container is working, I push changes to github and a new copy
 
Once the 'build-asterisk' container is working, check in changes to github and a new copy
will build at hub.docker.com automatically.
will build at hub.docker.com automatically.


Remember to tag which goes something like this
After version updates remember to tag which goes something like this
On hub.docker.com create a new build when new Asterisk versions are released.


  git tag -a rel1.0.x -m 'release 1.0.x of build-asterisk'
  git tag -a rel1.0.x -m 'release 1.0.x of build-asterisk'
Line 25: Line 22:
== Configuration ==
== Configuration ==


I keep the git repo for this part in Bellman because the current version is full of secrets.
I keep a private git repo for this part because the current version is full of secrets.
It's checked out as source/docker/docker-asterisk-wildsong with this command:


  git clone [email protected]:docker-asterisk-wildsong.git
  git clone [email protected]:docker-asterisk-wildsong.git


Edit environment settings in Dockerfile and add j2 config files that I created for Vastra.
Edit environment settings in the Dockerfile and adjust the j2 config files that were created originally for Vastra.
 
The current configuration is entirely file based because my home phone system is relatively static so messing with MySQL just seems like extra work for no return.
This configuration is entirely file based because my home phone system is relatively static so messing with MySQL just seems like extra work for no return.


The docker-asterisk container configures Asterisk based on templates
The docker-asterisk container configures Asterisk based on templates
Line 44: Line 41:
  docker build -t asterisk-wildsong .
  docker build -t asterisk-wildsong .


Start it up
== Start it up ==
 
Using the --net=host option is not a best practice because it exposes every port running on the docker machine.
It means it looks like Asterisk is just running on Bellman, not inside a container.
This is not 'best practices' but makes network problems go away. I am not sure if I need the "expose".
 
docker run -d --net=host --expose 10000-10101 --name=asterisk asterisk-wildsong
 
You should be able to see the SIP port(s) exposed


  docker run -d --net=host --expose=10000-10101 --name=asterisk asterisk-wildsong
  netstat -an |grep 5060
udp        0      0 0.0.0.0:5060            0.0.0.0:*
unix  2      [ ACC ]    STREAM    LISTENING    94552697 @/containerd-shim/moby/6de5485d98c7a6d642a10beead4e6111a8319f4ec9b84e8a23cf00ce9165060f/shim.sock@
unix  3      [ ]        STREAM    CONNECTED    94553455 @/containerd-shim/moby/6de5485d98c7a6d642a10beead4e6111a8319f4ec9b84e8a23cf00ce9165060f/shim.sock@


Make it reboot
If it seems to work then set it to reboot:


  docker update --restart unless-stopped asterisk
  docker update --restart unless-stopped asterisk


Debugging
== Running some tests ==
 
=== Debugging mode ===


Start the console then use commands
See also [[Asterisk debugging]] and [[Twilio]].


  docker exec -it asterisk asterisk -r
  docker exec -it asterisk asterisk -r
Line 60: Line 70:
  bellman*CLI> core set debug 10
  bellman*CLI> core set debug 10
  bellman*CLI> core set verbose 10
  bellman*CLI> core set verbose 10
bellman*CLI> pjsip


== Launch server ==
It's very useful to force a reload so you can see all the modules are loading correctly.
 
bellman*CLI> core reload


Using the --net=host option is not a best practice because it exposes every port running on the docker machine.
It's also useful to look at what the dialplan is
It means it looks like Asterisk is just running on Bellman, not inside a container.


  docker run -d --net=host --name=asterisk asterisk
  bellman*CLI> dialplan show
=== Outside call ===


I don't think I need any -p port mappings or --expose if I use --net=host, and though it's not "best practices"
==== From PBX to outside ====
it will make Asterisk networking problems go away pretty much.


== Testing ==
* Dial Twilio test numbers +1(650)489-4546 and +1(415)475-8378
** Check [https://www.twilio.com/console/sip-trunking/trunks/TKa9992c496d4a13177bd7792c443fb6ce/termination Twilio termination page] if it does not work.
* Dial out to cellphone
* Dial out to Google Voice


=== Outside call ===
==== Outside to PBX ====


Call from PSTN to 707-827-0001
* Try the [https://www.twilio.com/console/sip-trunking/trunks/TKa9992c496d4a13177bd7792c443fb6ce/origination Twilio origination] Make a Call button.
* Call from mobile to 707-827-0001
* Is it being logged at Twilio? '''YES'''
* Is it being logged at Twilio? '''YES'''
* Can I see the connection attempt in the Asterisk console? '''No'''
* Can I see the connection attempt in the Asterisk console? '''No'''
Line 82: Line 97:
* Two way audio?
* Two way audio?
* TODO Set up SMS and MMS message gateways???
* TODO Set up SMS and MMS message gateways???


=== Inside call, to PBX ===
=== Inside call, to PBX ===
Line 119: Line 135:
  docker exec -it asterisk asterisk -r
  docker exec -it asterisk asterisk -r


Or you can connect the usual way via a bash shell
Or you can run a sniffer
 
docker exec -it asterisk bash


  tcpdump -n not port 22 and not arp and not host 192.168.123.159
  docker exec -it asterisk tcpdump -n not arp


== Connected phones ==
== Connected phones ==

Revision as of 04:28, 25 February 2019

Read the Docker page if you don't know what Docker is.

Notes on building Asterisk executables from source, the old way: Building Asterisk. All this is built into my build-asterisk image and automated now.

Read the Twilio and Asterisk debugging pages too.

Building a configured Asterisk Docker container

I started with the github respoke/asterisk image as my starting point. Then I did my own version (brian32768/docker-build-asterisk in github or wildsong/asterisk in hub.docker.com) because I wanted to use the latest Asterisk and respoke does not appear to get updated.

On Bellman I keep the sources checked out here: source/docker/docker-build-asterisk

Once the 'build-asterisk' container is working, I push changes to github and a new copy will build at hub.docker.com automatically.

After version updates remember to tag which goes something like this On hub.docker.com create a new build when new Asterisk versions are released.

git tag -a rel1.0.x -m 'release 1.0.x of build-asterisk'
git push origin rel1.0.x

Configuration

I keep a private git repo for this part because the current version is full of secrets. It's checked out as source/docker/docker-asterisk-wildsong with this command:

git clone [email protected]:docker-asterisk-wildsong.git

Edit environment settings in the Dockerfile and adjust the j2 config files that were created originally for Vastra. The current configuration is entirely file based because my home phone system is relatively static so messing with MySQL just seems like extra work for no return.

The docker-asterisk container configures Asterisk based on templates in etc_asterisk.

cd source/docker/docker-asterisk-wildsong
edit Dockerfile to adjust environment
cd etc_asterisk
edit files
cd ..
docker rm -f asterisk-wildsong
docker build -t asterisk-wildsong .

Start it up

Using the --net=host option is not a best practice because it exposes every port running on the docker machine. It means it looks like Asterisk is just running on Bellman, not inside a container. This is not 'best practices' but makes network problems go away. I am not sure if I need the "expose".

docker run -d --net=host --expose 10000-10101 --name=asterisk asterisk-wildsong

You should be able to see the SIP port(s) exposed

netstat -an |grep 5060
udp        0      0 0.0.0.0:5060            0.0.0.0:*
unix  2      [ ACC ]     STREAM     LISTENING     94552697 @/containerd-shim/moby/6de5485d98c7a6d642a10beead4e6111a8319f4ec9b84e8a23cf00ce9165060f/shim.sock@
unix  3      [ ]         STREAM     CONNECTED     94553455 @/containerd-shim/moby/6de5485d98c7a6d642a10beead4e6111a8319f4ec9b84e8a23cf00ce9165060f/shim.sock@

If it seems to work then set it to reboot:

docker update --restart unless-stopped asterisk

Running some tests

Debugging mode

See also Asterisk debugging and Twilio.

docker exec -it asterisk asterisk -r

bellman*CLI> core set debug 10
bellman*CLI> core set verbose 10

It's very useful to force a reload so you can see all the modules are loading correctly.

bellman*CLI> core reload

It's also useful to look at what the dialplan is

bellman*CLI> dialplan show

Outside call

From PBX to outside

  • Dial Twilio test numbers +1(650)489-4546 and +1(415)475-8378
  • Dial out to cellphone
  • Dial out to Google Voice

Outside to PBX

  • Try the Twilio origination Make a Call button.
  • Call from mobile to 707-827-0001
  • Is it being logged at Twilio? YES
  • Can I see the connection attempt in the Asterisk console? No
    • Can I see the connection attempt being forwarded through the firewall? Don't know yet
  • Two way audio?
  • TODO Set up SMS and MMS message gateways???


Inside call, to PBX

  • Press voicemail button. Does prompt come back? YES
    • TODO -- I want it configured to bypass the user/pass prompt.

Inside call, station to station

I have two stations registering right now, the GXV phones.

  • 100 Ring all phones
  • 101 Studio phone 192.168.123.80 on wire
  • 102 eLab phone 192.168.123.76 on WIFI
  • 850 voice mail
  • Call to voice mail works.
  • Calling station to station works.
  • TODO -- GET SMART PHONE set up. Currently it fails to register
[Nov  6 06:56:21] NOTICE[262]: res_pjsip/pjsip_distributor.c:659 log_failed_request: Request 'REGISTER' from '<sip:[email protected]>' failed for '192.168.123.207:13411' (callid: [email protected]) - Failed to authenticate
[Nov  6 06:56:21] NOTICE[262]: res_pjsip/pjsip_distributor.c:659 log_failed_request: Request 'REGISTER' from '<sip:[email protected]>' failed for '192.168.123.207:13411' (callid: [email protected]) - No matching endpoint found

Voicemail

Logins fail with this error.

[Nov  6 06:54:09] WARNING[294][C-00000008]: app_voicemail.c:11191 vm_authenticate: Couldn't read username

Intercom calling

TODO

Console

You can connect to the Asterisk console directly with this command

docker exec -it asterisk asterisk -r

Or you can run a sniffer

docker exec -it asterisk tcpdump -n not arp

Connected phones

I don't know how to see what phones are registered with pjsip!??

I started a separate page for it, PJSIP.