Docker , asterisk and freepbx


Recommended Posts

Hello Unraid Community,

 

I have made the decision to move form flexraid (windows) to unraid, i am just collecting a few extra HDD to make the change over easier (will take a couple of months)

 

In the meanwhile i have been reading up on docker and thinking what i want to run onmy unraid box, most have already been covered (by needo) i see openHAB has also been given the docker treatment.

 

I would like to run asterisk on my box in a docker container, i couldn't find anyone on the unraid forum trying this so i thought i would have a go.

 

https://registry.hub.docker.com/u/dougbtv/asterisk/

https://registry.hub.docker.com/u/yvnicolas/asterisk/

 

I used the above two projects as my base and now have a docker file which builds and runs asterisk 11.6 based on the phusion image

 

https://github.com/Brownster/docker-asterisk-1/blob/master/asterisk/Dockerfile

 

I have started to have a go at including freepbx (i am trying to build as i type this):

 

https://github.com/Brownster/asterisk-freepbx/blob/master/Dockerfile

 

I would like some advise on how to improve the docker file, my understanding of security / usergroups is limited so don't know how to best setup what user asterisk runs

 

as specified in this thread:

 

http://lime-technology.com/forum/index.php?topic=33922.0

 

all suggestions very welcome

 

Many thanks

 

Marc

Link to comment

I have a problem with installing freepbx, to run the install you need asterisk running so i did:

 

#install free pbx and required mod to moh

WORKDIR /tmp/src

RUN wget http://mirror.freepbx.org/freepbx-$FREEPBXVER.tgz \

  && tar vxfz freepbx-$FREEPBXVER.tgz \

  && cd /tmp/src/freepbx \

  && ./start_asterisk start \

  && ./install_amp --installdb --username=asteriskuser --password=$ASTERISK_DB_PW \

  && amportal chown \

  && amportal a ma installall \

  && amportal a reload \

  && amportal a ma refreshsignatures \

  && amportal chown

  && ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3 \

  && amportal restart

 

 

but i get an error when it reaches a "is asterisk started" check:

 

freepbx/utests/InstallerTest.php

 

 

STARTING ASTERISK

Asterisk Started

Checking for PEAR DB..OK

Checking for PEAR Console::Getopt..OK

Using username: asteriskuser

Using password: *************************

Checking user..OK

Checking if Asterisk is running..FAILED

[FATAL] ./install_amp

Asterisk must be running. If this is a first time install, you should start

Asterisk by typing './start_asterisk start'

For upgrading, you should run 'amportal start'

INFO[0021] The command [/bin/sh -c wget http://mirror.freepbx.org/freepbx-$FREEPBXVER.tgz  && tar vxfz freepbx-$FREEPBXVER.tgz  && cd /tmp/src/freepbx  && ./start_asterisk start  && ./install_amp --installdb --username=asteriskuser --password=$ASTERISK_DB_PW  && amportal chown  && amportal a ma installall  && amportal a reload  && amportal a ma refreshsignatures  && amportal chown] returned a non-zero code: 1

 

Any ideas ??

 

Thanks

 

Marc

Link to comment

 

 

OK it runs all the way until Freepbx install

 

Then it complains it cannot connect to the db although the username and pass is correct

 

Checking for /etc/asterisk/asterisk.conf../etc/asterisk/asterisk.conf does not exist, copying default

OK

Reading /etc/asterisk/asterisk.conf..OK

Using asterisk as PBX Engine

Checking for Asterisk version..11.6

Checking for selinux..OK

Connecting to database..FAILED

Try running ./install_amp --username=user --password=pass  (using your own user and pass)

[FATAL] Cannot connect to database

 

 

 

 

DOCKER FILE:

#asterisk docker file

FROM phusion/baseimage:0.9.15

MAINTAINER marc brown <[email protected]>

 

# Set correct environment variables.

ENV HOME /root

ENV DEBIAN_FRONTEND noninteractive

ENV ASTERISKUSER asterisk

ENV ASTERISKVER 12

ENV FREEPBXVER 12.0.3

ENV ASTERISK_DB_PW pass123

ENV AUTOBUILD_UNIXTIME 1418234402

# Use baseimage-docker's init system.

CMD ["/sbin/my_init"]

 

#Install packets that are needed

RUN apt-get update && apt-get install -y build-essential curl libgtk2.0-dev linux-headers-`uname -r` openssh-server apache2 mysql-server mysql-client bison flex php5 php5-curl php5-cli php5-mysql php-pear php-db php5-gd curl sox libncurses5-dev libssl-dev libmysqlclient-dev mpg123 libxml2-dev libnewt-dev sqlite3 libsqlite3-dev pkg-config automake libtool autoconf git subversion unixodbc-dev uuid uuid-dev libasound2-dev libogg-dev libvorbis-dev libcurl4-openssl-dev libical-dev libneon27-dev libsrtp0-dev libspandsp-dev wget sox mpg123 libwww-perl php5 php5-json libiksemel-dev lamp-server^

 

#Add user

# grab gosu for easy step-down from root

RUN groupadd -r $ASTERISKUSER && useradd -r -g $ASTERISKUSER $ASTERISKUSER \

  && mkdir /var/lib/asterisk && chown $ASTERISKUSER:$ASTERISKUSER /var/lib/asterisk \

  && usermod --home /var/lib/asterisk $ASTERISKUSER \

  && rm -rf /var/lib/apt/lists/* \

  && curl -o /usr/local/bin/gosu -SL 'https://github.com/tianon/gosu/releases/download/1.1/gosu' \

  && chmod +x /usr/local/bin/gosu \

  && apt-get purge -y

 

#Install Pear DB

RUN pear uninstall db && pear install db-1.7.14

 

#build pj project

#build jansson

WORKDIR /temp/src/

RUN git clone https://github.com/asterisk/pjproject.git \

  && git clone https://github.com/akheron/jansson.git \

  && cd /temp/src/pjproject \

  && ./configure --enable-shared --disable-sound --disable-resample --disable-video --disable-opencore-amr \

  && make dep \

  && make \

  && make install \

  && cd /temp/src/jansson \

  && autoreconf -i \

  && ./configure \

  && make \

  && make install

 

# Download asterisk.

# Currently Certified Asterisk 11.6 cert 6.

RUN curl -sf -o /tmp/asterisk.tar.gz -L http://downloads.asterisk.org/pub/telephony/certified-asterisk/certified-asterisk-11.6-current.tar.gz

 

# gunzip asterisk

RUN mkdir /tmp/asterisk

RUN tar -xzf /tmp/asterisk.tar.gz -C /tmp/asterisk --strip-components=1

WORKDIR /tmp/asterisk

 

# make asterisk.

ENV rebuild_date 2015-01-29

# Configure

RUN ./configure 1> /dev/null

# Remove the native build option

RUN make menuselect.makeopts

RUN sed -i "s/BUILD_NATIVE//" menuselect.makeopts

# Continue with a standard make.

RUN make 1> /dev/null

RUN make install 1> /dev/null

RUN make config

RUN ldconfig 

 

RUN cd /var/lib/asterisk/sounds \

  && wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-extra-sounds-en-wav-current.tar.gz \

  && tar xfz asterisk-extra-sounds-en-wav-current.tar.gz \

  && rm -f asterisk-extra-sounds-en-wav-current.tar.gz \

  && wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-extra-sounds-en-g722-current.tar.gz \

  && tar xfz asterisk-extra-sounds-en-g722-current.tar.gz \

  && rm -f asterisk-extra-sounds-en-g722-current.tar.gz \

  && chown $ASRERISKUSER. /var/run/asterisk \

  && chown -R $ASTERISKUSER. /etc/asterisk \

  && chown -R $ASTERISKUSER. /var/lib/asterisk \

  && chown -R $ASTERISKUSER. /var/log/asterisk \

  && chown -R $ASTERISKUSER. /var/spool/asterisk \

#  && chown -R $ASTERISKUSER. /usr/lib/asterisk \

  && rm -rf /var/www/html

 

#mod to apache

#Setup mysql

RUN sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php5/apache2/php.ini \

  && cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_orig \

  && sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf \

  && service apache2 restart

 

 

#install free pbx and required mod to moh

WORKDIR /tmp

RUN wget http://mirror.freepbx.org/freepbx-$FREEPBXVER.tgz \

  && tar vxfz freepbx-$FREEPBXVER.tgz \

  && /etc/init.d/mysql start \

  && mysqladmin -u root create asterisk \

  && mysqladmin -u root create asteriskcdrdb \

  && mysql -u root -e "GRANT ALL PRIVILEGES ON asterisk.* TO asterisk@localhost IDENTIFIED BY 'pass123';" \

  && mysql -u root -e "GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asterisk@localhost IDENTIFIED BY 'pass1213';" \

  && mysql -u root -e "flush privileges;" \

  && cd /tmp/freepbx \

  && /usr/sbin/asterisk \

 

## fails on next step....

 

&&  ./install_amp --installdb --username=asterisk --password=pass123 \

  && amportal chown \

  && amportal a ma installall \

  && amportal a reload \

  && amportal a ma refreshsignatures \

  && amportal chown

  && ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3 \

  && amportal restart

 

EXPOSE 5060

 

CMD asterisk -f

 

 

Any ideas?

Link to comment

will have a look at doing that i will do a bit more playing first

 

mapping the freepbx config directory would be good to keep it out the container and probably a few other directories.

 

** update **

 

Decided not to map a load directories as most of the info is stored in sql, so at the moment i just mount one folder to allow easy backup of freepbx i have exposed ports 5060 80 and 10000-20000.

 

Still trying to decide best RUN command to use but something like:

 

sudo docker run --name freepbx -v /place/to/put/backup:/etc/freepbxbackup --publish-all=true -d -t brownster/freepbx12021

 

should work, it has taken all afternoon to upload the image to docker and will have to do it again as the current image  on docker doesn't have port 80 exposed, although i can see asterisk is running OK so that's a start!

 

Just running another build with all ports needed exposed. it will be tomorrow before i get chance to upload it, tbh if the upload time is anything to go on its probably quicker to build it form the docker file on github.

 

@Squid is there an xml template i can use?

 

Thanks

 

Marc

Link to comment

Ok so some success i now have freepbx running in a container on my laptop and it seems happy.

 

I ran in to a couple of warnings when i first ran the container which were easy to resolve and i have put the steps i took on git hub, i will look into the reasons why i got those warnings and see if i can do anything about them.

 

Apart from that i will do some actual testing with phones hopefully tomorrow.

 

to give it a try run:

 

sudo docker run --name freepbx -v /place/to/put/backup:/etc/freepbxbackup --net=host -d -t brownster/freepbx12021

 

changing /place/to/put/backup to something right for you.

 

you will then have freepbx running on the same ip as your host machine. you can login via that ip and set the username and password.

 

Word of warning in this image apache is listening on port 80 i will look at changing it to something else 8009 i will probably end up using unless that conflicts with another app?.

Link to comment
  • 3 months later...
  • 3 months later...
  • 1 month later...
  • 1 month later...

I'm having some luck with this

https://hub.docker.com/r/jmar71n/freepbx/

 

I've added it with bridge networking, mapped a free host port to 80 in the container, and forwarded SIP ports in.  Also added postfix and backup capabilities into the docker to backup to a mapped volume and that part is working so far.  Haven't setup phones or trunks yet, but that's freepbx configuration.  The docker part seems to be fine.

Link to comment
  • 9 months later...
  • 3 months later...
  • 3 months later...

Seems like an Asterisk/PBX docker is something that quite a few would like, but nobody has got to the idiot proof app stage.

 

Personally I'm looking for something that can talk to various VoIP services, and to an ATA.

 

Anyone with any pointers?

Link to comment
  • 3 weeks later...
  • 6 months later...

Been offline for a long long while,

 

Last week I fired up my Tower and now just migrating drives over to unraid  (from flexraid) once this is done, i will look at this again  with the latest version of freepbx.

 

Hopefully i'll have an update in a couple of weeks.

 

Is there a guide on creating the docker repo/xml for unraid?

Link to comment
10 hours ago, brownster said:

Been offline for a long long while,

 

Last week I fired up my Tower and now just migrating drives over to unraid  (from flexraid) once this is done, i will look at this again  with the latest version of freepbx.

 

Hopefully i'll have an update in a couple of weeks.

 

Is there a guide on creating the docker repo/xml for unraid?

Sound good !

 

There were tutorials in the docker engine fora, but not sure exactly where the best one is now. Worth asking the question over there for pointers, I don't think they bite.

 

Maybe for templates ...

 

Link to comment
  • 1 month later...

I had a look around and there are more freepbx dockers out there so have taken a short cut to getting up and running on freepbx 13 with unraid. going to try mima84/docker-freepbx docker build.

 

I knocked up a little xml so i could install through the unraid UI the container has persistence of data across container reboots but not across instances of the container. So if you modify the container once installed and a new container is created you will lose data.

 

here is the location if anyone else would like to try

 

https://github.com/Brownster/docker-templates/tree/master/brownster

 

Thanks for this Docker goes to MicMay - mima84,  https://hub.docker.com/r/mima84/docker-freepbx/

 

it is based on the docker image jmar71n_freepbx so thanks to Jason Martin https://hub.docker.com/r/jmar71n/freepbx/

 

Regards

 

image.png.dcd7cc9a24b0296e03f3c2cc4b9fd380.png

Edited by brownster
Link to comment

Hi,

 

Just tried this and get an error as follows:

"root@localhost:# /usr/local/emhttp/plugins/dynamix.docker.manager/scripts/docker run -d --name="FreePBX13" --net="bridge" -e TZ="Europe/Berlin" -e HOST_OS="unRAID" -p 8082:8082/tcp -p 5060:5060/tcp mima84/docker-freepbx

Unable to find image 'mima84/docker-freepbx:latest' locally
Pulling repository docker.io/mima84/docker-freepbx
/usr/bin/docker: Network timed out while trying to connect to https://index.docker.io/v1/repositories/mima84/docker-freepbx/images. You may want to check your internet connection or if you are behind a proxy..
See '/usr/bin/docker run --help'.

The command failed."

 

Tried a second time and it has installed ok. Let's see what we can do! Thanks for the Docker, I'm sure there will be a lot of interest.

Edited by rjstott
Add Info
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.