sms-handler/CONTAINER.md

89 lines
1.9 KiB
Markdown
Raw Normal View History

2024-12-01 13:12:34 +01:00
# Container
Use `podman` or `docker`:
```sh
2024-12-05 14:59:03 +01:00
podman run code.philo.ydns.eu/philorg/sms-handler
2024-12-01 13:12:34 +01:00
```
2024-12-05 05:41:57 +01:00
Parameters are given as environment variables, eg.:
2024-12-01 13:12:34 +01:00
```sh
2024-12-05 14:59:03 +01:00
podman run -e SMS_HANDLER_MAIL_SERVER_PORT=8025 -e SMS_HANDLER_MAIL_SENDER=snoopy@peanuts.com SMS_HANDLER_MAIL_TO=snoopy@peanuts.com code.philo.ydns.eu/philorg/sms-handler
2024-12-01 13:12:34 +01:00
```
## Container as a systemd service
Systemd can "orchestrate" containers easily thanks to podman.
### Rootless (as regular user)
2024-12-05 05:41:57 +01:00
For a rootless container, create a file in `.config/containers/systemd/sms-handler.container`.
The configuration is given as environment variables (email addresses `snoopy@peanuts.com` in this example):
2024-12-01 13:12:34 +01:00
```systemd
[Container]
ContainerName=sms-handler
Environment=SMS_HANDLER_MAIL_SENDER=snoopy@peanuts.com
Environment=SMS_HANDLER_MAIL_TO=snoopy@peanuts.com
2024-12-05 14:59:03 +01:00
Image=code.philo.ydns.eu/philorg/sms-handler
2024-12-01 13:12:34 +01:00
Network=podman
PublishPort=8025:8025
[Service]
Restart=always
[Install]
WantedBy=default.target
```
Request systemd to reload configuration, creating the service for this container:
```sh
systemctl --user daemon-reload
```
Start the container as a service:
```sh
systemctl start sms-handler.service
```
To start rootless containers at boot time, without the need for the user (snoopy) to log in:
```sh
sudo loginctl enable-linger snoopy
```
### Rootful (as root)
For a rootless container, create a file in `/etc/containers/systemd/sms-handler.container`:
```systemd
[Container]
ContainerName=sms-handler
Environment=SMS_HANDLER_MAIL_SENDER=snoopy@peanuts.com
Environment=SMS_HANDLER_MAIL_TO=snoopy@peanuts.com
2024-12-05 14:59:03 +01:00
Image=code.philo.ydns.eu/philorg/sms-handler
2024-12-01 13:12:34 +01:00
Network=podman
PublishPort=8025:8025
[Service]
Restart=always
[Install]
WantedBy=default.target
```
Request systemd to reload configuration, creating the service for this container:
```sh
sudo systemctl daemon-reload
```
Start the container as a service:
```sh
sudo systemctl start sms-handler.service
```