|
| 1 | +# Run LibreBooking with Podman |
| 2 | + |
| 3 | +This is an example how to run LibreBooking under podman container management. |
| 4 | +Below examples show both the quick way for running it directly with [podman |
| 5 | +run](https://docs.podman.io/en/latest/markdown/podman-run.1.html) command and |
| 6 | +the more permanent way |
| 7 | +[using systemd](https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html) |
| 8 | +which persists across reboots and is good for production. |
| 9 | + |
| 10 | +Both of the setups create private network for libreboot, and persistent storage |
| 11 | +for the congigs. |
| 12 | + |
| 13 | +# Podman Run for dev and testing |
| 14 | + |
| 15 | +Change the variables to your liking, and run the podman commands. If you want |
| 16 | +to do it just quicker, network is not necessary and volumes can be just given |
| 17 | +as local directories using `-v ~/dir:/path/in/container:z` instead of the first |
| 18 | +four commands. |
| 19 | + |
| 20 | +```sh |
| 21 | +podman network create librebooking --subnet 192.168.30.0/24 --gateway=192.168.30.1 |
| 22 | +podman volume create db-conf |
| 23 | +podman volume create lb-images |
| 24 | +podman volume create lb-reservations |
| 25 | + |
| 26 | +podman run --name mariadb-lb \ |
| 27 | + --detach \ |
| 28 | + --replace \ |
| 29 | + --network systemd-librebooking \ |
| 30 | + -e MYSQL_ROOT_PASSWORD=db_root_pwd \ |
| 31 | + -e TZ=Europe/Helsinki \ |
| 32 | + -e PUID=1000 \ |
| 33 | + -e PGID=1000 \ |
| 34 | + -e MYSQL_DATABASE=db \ |
| 35 | + -e MYSQL_USER=lb \ |
| 36 | + -e MYSQL_PASSWORD=lb-test \ |
| 37 | + -v db-conf:/config:U \ |
| 38 | + -p 3306:3306 \ |
| 39 | + docker.io/linuxserver/mariadb:10.6.13 |
| 40 | + |
| 41 | +podman run --name lb \ |
| 42 | + --detach \ |
| 43 | + --replace \ |
| 44 | + --hostname librebooking \ |
| 45 | + --network librebooking \ |
| 46 | + -e LB_DATABASE_NAME=db \ |
| 47 | + -e LB_DATABASE_USER=lb \ |
| 48 | + -e LB_DATABASE_PASSWORD=lb-test \ |
| 49 | + -e LB_DATABASE_HOSTSPEC=mariadb-lb \ |
| 50 | + -e LB_INSTALL_PASSWORD=installme \ |
| 51 | + -e LB_LOGGING_FOLDER=/var/log/librebooking \ |
| 52 | + -e LB_LOGGING_LEVEL=DEBUG \ |
| 53 | + -e LB_LOGGING_SQL=false \ |
| 54 | + -e LB_DEFAULT_TIMEZONE=Europe/Helsinki \ |
| 55 | + -p 8080:8080 \ |
| 56 | + --volume lb-images.volume:/var/www/html/Web/uploads/images \ |
| 57 | + --volume lb-reservation.volume:/var/www/html/Web/uploads/reservation \ |
| 58 | + --volume ~/librebooking-conf:/config:U \ |
| 59 | + docker.io/librebooking/librebooking:develop |
| 60 | +``` |
| 61 | + |
| 62 | +# Production way with systemd |
| 63 | + |
| 64 | +This method persists over reboots. |
| 65 | +[Automatic updates](https://docs.podman.io/en/latest/markdown/podman-auto-update.1.html) |
| 66 | +for container images are not enabled in this example. Try it also, it's handy. |
| 67 | + |
| 68 | +## Create network file |
| 69 | + |
| 70 | +```sh |
| 71 | +cat >> ~/.config/containers/systemd/librebooking.network<<EOF |
| 72 | +[Unit] |
| 73 | +Description=Librebooking Network |
| 74 | +
|
| 75 | +[Network] |
| 76 | +Subnet=192.168.30.0/24 |
| 77 | +Gateway=192.168.30.1 |
| 78 | +Label=app=librebooking |
| 79 | +EOF |
| 80 | +``` |
| 81 | + |
| 82 | +## create volume for DB |
| 83 | + |
| 84 | +```sh |
| 85 | +cat >> ~/.config/containers/systemd/mariadb-lb.volume<<EOF |
| 86 | +[Volume] |
| 87 | +Driver=local |
| 88 | +Label=app=librebooking |
| 89 | +EOF |
| 90 | +``` |
| 91 | + |
| 92 | +## Create DB container conf |
| 93 | + |
| 94 | +```sh |
| 95 | +cat >> ~/.config/containers/systemd/mariadb-lb.container<<EOF |
| 96 | +[Unit] |
| 97 | +Description=MariaDB container |
| 98 | +
|
| 99 | +[Container] |
| 100 | +Image=docker.io/linuxserver/mariadb:10.6.13 |
| 101 | +Environment=MYSQL_ROOT_PASSWORD=db_root_pwd |
| 102 | +Environment=MYSQL_USER=lb |
| 103 | +Environment=MYSQL_PASSWORD=lb-test |
| 104 | +Environment=MYSQL_DATABASE=db |
| 105 | +Environment=PUID=1000 |
| 106 | +Environment=PGID=1000 |
| 107 | +Volume=mariadb-lb.volume:/config:U |
| 108 | +Network=librebooking.network |
| 109 | +PublishPort=3306:3306 |
| 110 | +Label=app=librebooking |
| 111 | +# AutoUpdate=registry |
| 112 | +
|
| 113 | +[Service] |
| 114 | +Restart=on-failure |
| 115 | +EOF |
| 116 | +``` |
| 117 | + |
| 118 | +## Create Images Volume |
| 119 | + |
| 120 | +```sh |
| 121 | +cat >> ~/.config/containers/systemd/lb-images.volume<<EOF |
| 122 | +[Volume] |
| 123 | +Driver=local |
| 124 | +Label=app=librebooking |
| 125 | +EOF |
| 126 | +``` |
| 127 | + |
| 128 | +## Create Reservations Volume |
| 129 | + |
| 130 | +```sh |
| 131 | +cat >> ~/.config/containers/systemd/lb-reservation.volume<<EOF |
| 132 | +[Volume] |
| 133 | +Driver=local |
| 134 | +Label=app=librebooking |
| 135 | +EOF |
| 136 | +``` |
| 137 | + |
| 138 | +## Create LB container file |
| 139 | + |
| 140 | +```sh |
| 141 | +cat >> ~/.config/containers/systemd/lb.container<<EOF |
| 142 | +[Unit] |
| 143 | +Description=Librebooking container |
| 144 | +Requires=mariadb-lb.service |
| 145 | +After=mariadb-lb.service |
| 146 | + |
| 147 | +[Container] |
| 148 | +HostName=librebooking |
| 149 | +Image=docker.io/librebooking/librebooking:develop |
| 150 | +Network=librebooking.network |
| 151 | +Environment=LB_DATABASE_NAME=db |
| 152 | +Environment=LB_DATABASE_USER=lb |
| 153 | +Environment=LB_DATABASE_PASSWORD=lb-test |
| 154 | +Environment=LB_DATABASE_HOSTSPEC=systemd-mariadb-lb |
| 155 | +Environment=LB_INSTALL_PASSWORD=installme |
| 156 | +Environment=LB_LOGGING_FOLDER=/var/log/librebooking |
| 157 | +Environment=LB_LOGGING_LEVEL=DEBUG |
| 158 | +Environment=LB_LOGGING_SQL=false |
| 159 | +Environment=LB_DEFAULT_TIMEZONE=Europe/Helsinki |
| 160 | +PublishPort=8080:8080 |
| 161 | +Label=app=librebooking |
| 162 | +Volume=lb-images.volume:/var/www/html/Web/uploads/images |
| 163 | +Volume=lb-reservation.volume:/var/www/html/Web/uploads/reservation |
| 164 | +Volume=%h/librebooking-conf:/config:U |
| 165 | +# AutoUpdate=registry |
| 166 | +# User=1000:1000 |
| 167 | +
|
| 168 | +
|
| 169 | +[Install] |
| 170 | +WantedBy=multi-user.target |
| 171 | +
|
| 172 | +[Service] |
| 173 | +Restart=on-failure |
| 174 | +EOF |
| 175 | +``` |
| 176 | + |
| 177 | +## Create ports.conf to override apache port |
| 178 | + |
| 179 | +```sh |
| 180 | +cat >> ~/lb-ports.conf<<EOF |
| 181 | +# If you just change the port or add more ports here, you will likely also |
| 182 | +# have to change the VirtualHost statement in |
| 183 | +# /etc/apache2/sites-enabled/000-default.conf |
| 184 | +
|
| 185 | +Listen 8080 |
| 186 | +
|
| 187 | +<IfModule ssl_module> |
| 188 | + Listen 8443 |
| 189 | +</IfModule> |
| 190 | +
|
| 191 | +<IfModule mod_gnutls.c> |
| 192 | + Listen 8443 |
| 193 | +</IfModule> |
| 194 | +EOF |
| 195 | +``` |
| 196 | + |
| 197 | +## Create virtual server conf to override apache port |
| 198 | + |
| 199 | +```sh |
| 200 | +cat >> ~/ lb-000-default.conf<<EOF |
| 201 | +<VirtualHost *:8080> |
| 202 | + ServerAdmin webmaster@localhost |
| 203 | + DocumentRoot /var/www/html |
| 204 | + ErrorLog ${APACHE_LOG_DIR}/error.log |
| 205 | + CustomLog ${APACHE_LOG_DIR}/access.log combined |
| 206 | +</VirtualHost> |
| 207 | +EOF |
| 208 | +``` |
| 209 | + |
| 210 | +## Create permanent conf dir for LB |
| 211 | + |
| 212 | +```sh |
| 213 | +mkdir ~/librebooking-conf |
| 214 | +``` |
| 215 | + |
| 216 | +## Start the services |
| 217 | + |
| 218 | +Now we have all the config files done for systemd. Next we reload the daemon, and start the services: |
| 219 | + |
| 220 | +```sh |
| 221 | +systemctl --user daemon-reload |
| 222 | +systemctl --user start mariadb-lb |
| 223 | +systemctl --user start lb |
| 224 | +``` |
| 225 | + |
| 226 | +## Enable autostart at boot |
| 227 | + |
| 228 | +To make the systemd start the containers automatically at boot you need to |
| 229 | +enable lingering the the user and enable the services: |
| 230 | + |
| 231 | +```sh |
| 232 | +sudo loginctl enable-linger $USER |
| 233 | +systemctl --user enable --now mariadb-lb |
| 234 | +systemctl --user enable --now lb |
| 235 | +``` |
| 236 | + |
| 237 | +## Logs |
| 238 | + |
| 239 | +If you want to see the logs, you can use `podman logs ...` or use `journalctl --user -u lb`. You can also modify the conf file in ~/librebooking-conf/config.php, and restart the service with `systemctl --user restart lb`. |
| 240 | + |
| 241 | +# Connect to Librebooking |
| 242 | + |
| 243 | +At this point the system is running at http://<hostname>:8080. |
| 244 | + |
| 245 | +*Note: I tested the config on Fedora 43.* |
0 commit comments