Spinning up docker containers from http requests reddit / selfhosted ---------------------------------------------------------------------- thefatsun-burntguy · 2023-12-05 23:06 not much more to say honestly, was having a talk with some coworkers and came up with the question of scaling to zero in self hosted docker containers (keeping a proxy like nginx up and resuming the containers when requests come in with a TTL of 15 minutes before stopping the containers again).The questions are manyfold; This is very common in the enterprise space, can this be replicated in a small selfhosted environment? can this be done with docker compose or is something more advanced like kubernetes required for this?anyone have experience in doing a deployment of this kind? any and all information that you guys can throw my way are appreciated. thanks for reading ;) ---------------------------------------------------------------------- thekrautboy · 2023-12-05 23:51 https://github.com/vmorganp/Lazytainer exists as example, and some reverse proxies have plugins for this like Traefik with Sablier, or Sablier as standalone. Not hard to find with a simple search here. ---------------------------------------------------------------------- thefatsun-burntguy · 2023-12-05 23:54 thx will look at it later. sorry for not doing more research about it, all the stuff i looked up basically was messing with system.d and custom python scripts so i was looking for less bespoke solutions. now that i know the name sablier exists, all my searches have become much more useful. ---------------------------------------------------------------------- DeadEyePsycho · 2023-12-05 23:56 Not sure if it is exactly what you want but the built in Swarm mode has scaling. ---------------------------------------------------------------------- thekrautboy · 2023-12-05 23:57 Okay. ---------------------------------------------------------------------- maximus459 · 2023-12-06 03:56 Didn't know traefik had this feature ---------------------------------------------------------------------- IsPhil · 2023-12-06 04:39 Might be more complex than what you want, but I think kubernetes does basically what you want. You're looking for container orchestration basically. You could combine it with ansible, I've heard good things about but have not used it, but there are fans that say it can make the process easier. There are some great videos from Jeff Geerling on YouTube for both of these topics. Alternatively, you could make a script that calls docker commands for what you're describing for more diy stuff, or search for container orchestration. ---------------------------------------------------------------------- floppydiet · 2023-12-06 04:45 Nomad should be able to do this too ---------------------------------------------------------------------- thekrautboy · 2023-12-06 05:00 Okay. ---------------------------------------------------------------------- thefatsun-burntguy · 2023-12-06 10:22 +1 upvote for mentioning red shirt jeff i was under the impression that ansible was more oriented towards having a more reliable installation script and configuration(basically what im doing with docker images). given what others have mentioned i think that ill give the others a shot before this. in regards to kubernetes, i have used it in the past but only for something relatively simple and this feels more like a niche usecase(ive scaled to 1 un k8 before but didnt know if scale to 0 was possible) still thanks for the comment ;) ---------------------------------------------------------------------- thefatsun-burntguy · 2023-12-06 10:29 a quick read over their docs tells me it should be able to do this. thx for the comment ---------------------------------------------------------------------- ohmer123 · 2023-12-06 11:37 And can be Terraform'ed https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs /resources/service ---------------------------------------------------------------------- -__-_--__--_ · 2023-12-06 12:10 I'll keep it short, look at FreeBSD jails. Maybe it's what you're looking for ---------------------------------------------------------------------- _avee_ · 2023-12-06 13:01 Out of curiosity, what would be a benefit of this? In enterprise space the clear benefit is freeing resources and shutting down hardware when demand is down. But in selfhosted space you are probavbly running a (single) server anyway and for most services an idle container doesn't consume significantly more power than a shut down one. ---------------------------------------------------------------------- thefatsun-burntguy · 2023-12-06 13:27 Sound. thats it im running my config on a cluster thats 2 15+ old computers and they make a ton of noise when running the containers because the fans spool up. i even managed to get one of them to shutdown and turn on with a raspberry pi and wakeonlan a couple of years back. is this a bad solution? probably, isnt it just easier to buy modern hardware and run it there with passive cooling? most assuredly. But ill be damned if i cant create an enterprise grade over engineered mess in my basement, thats what the selfhosted spirit is all about isn't it? ---------------------------------------------------------------------- IsPhil · 2023-12-06 14:24 Yeah, ansible is probably overkill, but yeah, it is an automation configuration tool from what I know. I've never used it, both of these are overkill for what I do, but kubernetes can definitely do what you want. I did see some other comments with alternatives, so those might work. But hey, if all else fails, you can fall back on Kubernetes. I was mentioning ansible because it is a popular tool to use with kubernetes. Hope you post back some time later with what solution you end up getting and how its working. ---------------------------------------------------------------------- kon_dev · 2023-12-06 16:31 Did you consider running knative or openfaas? https://github.com/openfaas/faas But might be a bit to heavyweight for what you describe. ---------------------------------------------------------------------- thefatsun-burntguy · 2023-12-07 01:41 given the other solutions presented i think ill let the hole self hosted serverless for someone that smarter than me, particularly because building a set of triggers that are smart enough spool down the containers seems like a headache and prone to breaking. having said that, it's really cool that you can self host lamdas, i used to think those were vendor lock in exclusive. anyway thanks for the suggestion