Running OTmonitor in docker

Docker is an open platform for developing, shipping, and running applications. It is assumed that anyone interested in running OTmonitor in docker is already familiar with the ecosystem and has a working docker setup.

General use

The general command to start an OTmonitor docker container will look something like:

    docker run -d \
      --user $(id -u):$(id -g) \
      -p 2380:8080 \
      -e TZ=Europe/Amsterdam \
      -v $HOME/.config/otmonior:/data \
      -v $HOME/otlogs:/log \
      hvxl/otmonitor:stable
    
Note: Make sure the specified directories exist before starting the container. If not, they will be created by the docker daemon, which generally runs as root. As a result, the user will not have sufficient permissions to create files in these directories.

Explanation of the used arguments

-d
Run the container in the background and print the new container ID.
--user $(id -u):$(id -g)
Run OTmonitor as the current user, rather than root.
-p 2380:8080
OTmonitor runs its web server on port 8080. This command maps that port to a port on the host. Feel free to use another port than 2380.
-e TZ=Europe/Amsterdam
Messages in the message log are displayed with a time stamp. By default this will reflect the UTC time zone. Set the TZ environment variable using this option to show the time stamps for the local time zone.
-v $HOME/.config/otmonior:/data
Any configuration changes you make in a running container will be lost when the image is restarted, unless those changes are saved outside of the container. Internally, the OTmonitor image uses the /data directory to store its configuration files (otmonitor.conf and auth.db). This option maps that directory to .config/otmonior in the user's home directory on the host. Any directory the user has write permissions for may be substituted, if desired.
-v $HOME/otlogs:/log
To avoid poluting the configuration directory with log files, a second directory is provided for saving log files. Internally this is the /log directory. This option can be used to map that directory to a directory on the host.
hvxl/otmonitor:stable
This is the name of the OTmonitor image. The "stable" tag represents the last released version. You may also specify a specific version, e.g.: "hvxl/otmonitor:6.5". Whenever a change to the program is checked in on github, a new image is automatically generated via github actions. This image is uploaded with the "latest" tag. As that is the default tag, you can get all the newest features and bugs by using the "hvxl/otmonitor" image.

Fabricated/anticipated questions

This section was created along with the rest of the description. So there were no frequently asked questions yet. But I thought it might be useful to have a "FAQ" anyway.
  1. How do I create the initial otmonitor.conf file?
  2. Can I just map the otmonitor.conf file instead of a whole directory?
  3. Do I still have to specify the -p option if I just want to use port 8080?
  4. I configured a different web server port, but it reverts to 8080 after a restart.
  5. How can I use my existing otmonitorrc configuration file when following the advice to map a configuration directory?
  6. I need to collect a log file. What configuration should I use?
  7. I collected a log file in /log, but I forgot to map the directory in the docker run command. How do I get the file?
  8. My OTGW has a name on the network, but I cannot connect to it using its name in otmonitor.
  9. How can I run the image, but start a shell instead of the otmonitor program?
  10. How can I install a web page that I have modified in the image?
How do I create the initial otmonitor.conf file?
With OTmonitor docker images from other sources it used to be necessary to provide a minimal otmonitor.conf file to start the web server. The hvxl/otmonitor image starts the web server by default. So you can just access the web pages by pointing your browser to the port you specified in the -p option. Then go to the "Configure" link and set things up as you like.
Can I just map the otmonitor.conf file instead of a whole directory?
This used to be the advice for other OTmonitor docker images. It is possible, but there are a few pitfalls with that technique:
  • Make sure the file you map on the host exists, otherwise the docker deamon will create a directory. That will make it impossible for OTmonitor to save the configuration file.
  • In addition to otmonitor.conf, OTmonitor also creates a database file for managing users with web access. If that file is not stored outside the container, all user information is lost when the image is restarted.
Do I still have to specify the -p option if I just want to use port 8080?
Yes. Docker doesn't automatically expose the web server port to the outside world. To use port 8080, specify: -p 8080:8080.
I configured a different web server port, but it reverts to 8080 after a restart.
By default, OTmonitor is executed with a command line option to start the web server on port 8080. This overrides the setting in the configuration file. The default command line option is discarded if you append any arguments to the docker run command. You could use "-l", for example.
How can I use my existing otmonitorrc configuration file when following the advice to map a configuration directory?
You can append arguments to the docker run command that will be passed to OTmonitor. To use a configuration file called otmonitorrc, add "-f /data/otmonitorrc". You still have to specify the directory as /data, as that is the internal path that is mapped to your external configuration directory. You may also have to change the port mapping if your configuration file uses a different port for the web server:
    docker run --user $(id -u):$(id -g) -dp 4280:4280 -e TZ=Europe/Amsterdam \
      -v $HOME/otlogs:/log -v $HOME/.config/otmonitor:/data \
      hvxl/otmonitor:stable -f /data/otmonitorrc
    
I need to collect a log file. What configuration should I use?
In the Logging configuration tab, specify "/log" as the log file directory. Use whatever name pattern suits your needs. Don't include any directories in the name pattern. Then check the Logfile box. Now the logs will be created in the directory you mapped to /log in the docker run command.
I collected a log file in /log, but I forgot to map the directory in the docker run command. How do I get the file?
You can use the "docker cp" command to copy the log file out of the container:
    docker cp $(docker ps -qf ancestor=hvxl/otmonitor:stable):/log/otlog.txt .
    
My OTGW has a name on the network, but I cannot connect to it using its name in otmonitor.
If you run your docker daemon on the same machine that provides the name service for your local network (e.g. using dnsmasq), your /etc/resolv.conf probably points to localhost (127.0.0.1 or ::1). Docker picks up this file for use by your containers. But inside a container, localhost is not the same thing as it is on the host. To fix this, add the --dns IP-address option to the docker run command. Specify the external IP address of your machine.
How can I run the image, but start a shell instead of the otmonitor program?
The image specifies the otmonitor command as its entry point. To override that, you have to use the --entrypoint option. When running a shell, you will also want to run interactively:
    docker run -it --entrypoint=sh hvxl/otmonitor
    
How can I install a web page that I have modified in the image?
You can create your own image based on the hvxl/otmonitor image by creating a Dockerfile:
    FROM hvxl/otmonitor
    RUN mkdir -p /usr/local/bin/html
    COPY status.html.tmpl footer.inc /usr/local/bin/html/.
    
Then build the image using:
    docker build -t otmon-priv .
    
Alternatively, run the image as root, make the necessary changes, and create a new image from the modified container:
    docker run -d hvxl/otmonitor
    docker exec $(docker ps -ql) mkdir /usr/local/bin/html
    docker cp status.html.tmpl $(docker ps -ql):/usr/local/bin/html
    docker cp footer.inc $(docker ps -ql):/usr/local/bin/html
    docker commit $(docker ps -ql) otmon-priv