Running a Container
To run a Docker image in a Container:
To maintain persistence of a Zixi Broadcaster’s configs when the Docker container is terminated (via the docker rm command or the host system being powered off while the container is running), the broadcaster-config.xml, broadcaster-info.xml, and broadcaster.lic files need to be stored on the host system so they will be available to a newly started container. The approach used here is inside the Docker image we create a configs directory and then symlink those three files from the Broadcaster install directory, their default location, into the configs directory. Then we map that configs directory to the host similar to how we map the logs and files directories. A caveat to this approach is upon the first time running, the Broadcaster does not work with a symlink to an empty broadcaster-config.xml file. To satisfy the Broadcaster at initial startup, we copy a minimal broadcaster-config.xml file (see Appendix B) into the configs folder on the host that is mapped to the configs folder inside the container. The Broadcaster will subsequently update the config file with user settings. Copy the config file as shown below:
# cp broadcaster-config-template-raspberry.xml ~/bxconfigs/broadcaster-config-template.xml
Run the image and create a new container using a run command as shown below:
# docker run --net=host --volume ~/bxconfigs:/zixi_broadcaster-raspberry/configs --volume ~/bxlogs:/zixi_broadcaster-raspberry/logs --volume ~/bxfiles:/zixi_broadcaster-raspberry/files --name Broadcaster_<version_number> zixi_broadcaster:<version_number>
The run command has many options. Below is a description of the options used in this example:
--net
-- This option allows you to choose the type of networking used in the container.With “host” mode all containers on the host share the hosts networking configuration and to access a container you would use the host’s IP address, such as 192.168.10.20:4444 for the Broadcaster UI. If you have multiple Broadcaster containers running on the same host you would need to configure the Broadcaster in each container to use a different port for the UI and different ports for Zixi or other input and output protocols. Also, you will need to configure the firewall on the host to protect the running containers from external threats.
With “bridged” mode, which is the default if you do not specify the --net option, each container will have its own network that exists on host. The host will be able to directly communicate with the containers but any other device on the network cannot communicate with the containers unless IP forwarding is enabled. See this link for more information on IP forwarding on the host. Networking in bridged mode will be slightly less efficient than host mode because there is an additional layer of networking redirection.
--volume
-- This option allows you to mount directories inside the container to directories on your host system. In this example we are mounting the logs directory and the files directory from the Broadcaster installation directory to local folders which makes it easy to inspect logs or retrieve recordings from the Broadcaster running in the container.--name
-- This option gives the container a human readable name when looking at the Docker process table.--publish
-- This option is only valid with bridged mode networking. In the dockerfile you will see that we exposed typical ports that you would use with the Broadcaster. However, those ports will only be exposed to the host if you also publish them in the run command with command line options on the docker run command, such as the following:--publish 4444:4444/TCP --publish 2088:2088/UDP
For host mode networking, all network settings are controlled on the host itself and --publish is ignored.
-d --restart unless-stopped
- These options can be added so the Docker container will automatically restart if the host system is powered off and back on--mac-address
- If the host system presents a new mac-address every time it is restarted, this will invalidate the licensing and an option like --mac-address 02:42:ac:11:00:de can be used to force the same mac address every time.Image ID – The last option is the image ID which you see in the images table above.
Upon using the Docker run command, there will now be a running Docker container.
You can see the list of all running containers using the following command:
# docker ps
The output will be similar to the following (with different IDs):
CONTAINER IMAGE COMMAND CREATED STATUS PORTS NAMES f8f30e025166 855f142a53a7 "./zixi_broadcaster-…" 21 minutes ago Up 21 minutes Broadcaster_16.4.44543
In host mode the ports will be empty. In bridged mode the actual ports that were published will be shown. In the shell window where you issued the docker run command you will see any content going to STDOUT and STDERR inside the container on STDOUT of the docker run process on the host.
With the container running, you can log into the Broadcaster web UI at port 4444. In host mode you will use the IP address of the host itself. In bridged mode you can use a command like the following to see the IP address of the running container:
# docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}' $(docker ps -aq)