0

I've been looking into setting up a data volume for a Docker container that I'm running on my server. The container is from this FreePBX image https://hub.docker.com/r/jmar71n/freepbx/ Basically I want persistent data so I don't lose my VoIP extensions and settings in the case of Docker stopping. I've tried many guides, ones here on stack overflow, and on the Docker manpages, but I just can't quite get it to work.

Can anyone help me with what commands I need to run in order to attach a volume to the FreePBX image I linked above?

user3608260
  • 143
  • 1
  • 1
  • 6

2 Answers2

0

You can do this by running a container with the -v option and mapping to a host directory - you just need to know where the container's storing the data.

Looking at the Dockerfile for that image, I'm assuming that the data you're interested in is stored in MySql. In the MySql config the data directory the container's using is /var/lib/mysql.

So you can start your container like this, mapping the MySql data directory to /docker/pbx-data on your host:

> docker run -d -t -v /docker/pbx-data:/var/lib/mysql jmar71n/freepbx                  
20b45b8fb2eec63db3f4dcab05f89624ef7cb1ff067cae258e0f8a910762fb1a   

Use docker inpect to confirm that the mount is mapped as expected:

> docker inspect --format '{{json .Mounts}}' 20b                                       
[{"Source":"/docker/pbx-data",
"Destination":"/var/lib/mysql",
"Mode":"","RW":true,"Propagation":"rprivate"}]                                                                   

When the container runs it bootstraps the database, so on the host you'll be able to see the contents of the MySql data directory the container is using:

> ls -l /docker/pbx-data                                                               
total 28684                                                                            
-rw-r----- 1 103 root           2062 Sep 21 09:30 20b45b8fb2ee.err                     
-rw-rw---- 1 103 messagebus 18874368 Sep 21 09:30 ibdata1                              
-rw-rw---- 1 103 messagebus  5242880 Sep 21 09:30 ib_logfile0                          
-rw-rw---- 1 103 messagebus  5242880 Sep 21 09:30 ib_logfile1                          
drwx------ 2 103 root           4096 Sep 21 09:30 mysql                                
drwx------ 2 103 messagebus     4096 Sep 21 09:30 performance_schema

If you kill the container and run another one with the same volume mapping, it will have all the data files from the previous container, and your app state should be preserved.

I'm not familiar with FreePBX, but if there is state being stored in other directories, you can find the locations in config and map them to the host in the same way, with multiple -v options.

Elton Stoneman
  • 17,906
  • 5
  • 47
  • 44
0

Hi Elton Stoneman and user3608260!

Yes, you assuming correctly for data saves in Mysql (records, users, configs, etc.).

But in asterisk, all configurations are saved in files '.conf' and similars.

In this case, the archives looked for user3608260 are storaged in '/etc/asterisk/*'

Your answer is perfectly with more one command: -v /local_to_save:/etc/asterisk

the final docker command:

docker run -d -t -v /docker/pbx-data:/var/lib/mysql -v /docker/pbx-asterisk:/etc/asterisk jmar71n/freepbx

[Assuming /docker/pbx-asterisk is a host directory. ]