Is there a way to launch an app on connect so it can stay closed when unused but still have the web access running?
Some apps don't really need to be runnign 24/7, is there a way to set up a container so that you can quit the app and the docker goes into an idle mode with just a login page, and when someone logs in it relaunches the app automatically?
One solution I can think of is putting your own reverse proxy in front of it. E.g. Nginx can execute LUA/shell scripts https://www.baeldung.com/ops/nginx-run-shell-script
You can then write your own script which starts the main application container and also stops the container if there has not been a request for some time.
Yeah that could be an easier solution than doing something built-in in the baseimage.
Note that there is also the cases of VNC clients. The web is not the only interface.
True that! Don't know VNC and the RFB protocoll enough, but is there no way to connect to a VNC server through a proxy as well?
Is it not possible to set a docker container that basically goes to sleep until it detects an incoming ping through http and/or vnc?
Or even just one where instead of launching the app it launches a button to launch the app, which pops up again when the app is closed
Seems like there exist already tools for this, so you don't need to write your own scripts. Basically they are reverse proxies.
https://github.com/vmorganp/Lazytainer https://github.com/NathanDecou/wakontainer https://sablierapp.dev/
But I don't know if they also are able to handle the case with VNC client connections.
Ok, I tried it now with Lazytainer
version: "3"
services:
lazytainer:
container_name: lazytainer
image: ghcr.io/vmorganp/lazytainer:master
environment:
- VERBOSE=true
ports:
- 5800:5800
- 5900:5900
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
labels:
- "lazytainer.group.xterm.sleepMethod=stop"
- "lazytainer.group.xterm.ports=5800,5900"
- "lazytainer.group.xterm.inactiveTimeout=30" # 30 seconds
- "lazytainer.group.xterm.minPacketThreshold=10"
- "lazytainer.group.xterm.pollRate=5"
xterm:
image: docker-xterm
build:
dockerfile: Dockerfile
context: .
network_mode: service:lazytainer
restart: unless-stopped
labels:
- "lazytainer.group=xterm"
depends_on:
- lazytainer
It basically works. I can connect through web and VNC. After the container is stopped, I can wake it up and by connecting. Configuration is a little bit tricky and one has to play around with the settings in order to find a balance between not staying awake all the time and being able to wake it up. What I also have seen is that pause instead of stop works better for a vnc connection in order to wake it up. But with VNC it was most of the time not really realiable to wake it up, but I had to try to cannot multiple times in order to generate enough traffic that lazytrainer detects a enough packets for waking up. It helps to explicitly send tcp packets before trying to connect. E.g. when I add
bash -c 'for run in {1..3}; do dd if=/dev/urandom count=100 bs=100 > /dev/tcp/127.0.0.1/5900 ; done; sleep 5'
as "Before connecting" command in Remmina, it reliable wakes up before establising the VNC connection.