Skip to content

Instantly share code, notes, and snippets.

@Jip-Hop
Last active August 27, 2024 16:40
Show Gist options
  • Save Jip-Hop/4704ba4aa87c99f342b2846ed7885a5d to your computer and use it in GitHub Desktop.
Save Jip-Hop/4704ba4aa87c99f342b2846ed7885a5d to your computer and use it in GitHub Desktop.
Persistent Debian 'jail' on TrueNAS SCALE to install software (docker-compose, portainer, podman, etc.) with full access to all files via bind mounts. Without modifying the host OS at all thanks to systemd-nspawn!
@Jip-Hop
Copy link
Author

Jip-Hop commented Feb 28, 2023

Hi. You should not need to run systemd-nspawn yourself. The jlmkr.py script takes care of that. You should create a jail with jlmkr.py create. Then also specify the bind mounts when the wizard asks you to. Then run jlmkr.py start dockerjail on each reboot. Hope that makes sense.

@Talung
Copy link

Talung commented Feb 28, 2023

ah ok. Must have missed that part of the setup. Or maybe I skipped it just to get it working for testing. Is there a way to update it now, or should I just make a new one. Thing is, I would probably run into situations where I would want to add more mounts in at a later stage.

I have everything else setup with no issues. So script and documentation was fine in that respect. thanks

EDIT. went through install again and saw what was happening. It is way easier than I thought, just need to modify the config file and add: systemd_nspawn_user_args=--bind='/mnt/pond/appdata/' for the various folders or --bind-ro=

Added this part for anybody else that runs into the same issue. :)

@Jip-Hop
Copy link
Author

Jip-Hop commented Feb 28, 2023

Exactly! Glad you got it solved :)

@Talung
Copy link

Talung commented Mar 1, 2023

Quick update for you. Everything is working great. Been able to move all the native docker stuff into the jail without really needing to change much. Even the "internal networking" I setup went through just fine ie. in portainer "networks". Haven't need to use Traefek or anything like that, works as it did before. I haven't tried any nvidia passthrough yet and have noticed that you have a recent update on that, so will look at that at a later stage.

I did notice that there is no daemon.json file in the container and am assuming I just need to add in my copy from "enable-docker.sh" in there. I haven't done that yet.

Also, I have noticed all the images are stored with the jail, which means if I recreate the jail I would need to re-download all the images again. All my data is outside of it, so not really an issue tbh, except during development stages.

Just wanted to add my thanks to you for doing this. 👍

@Jip-Hop
Copy link
Author

Jip-Hop commented Mar 1, 2023

Good to hear! And convenient that you have a nvidia GPU :) Indeed still in the process of getting that working properly.

I don't know what you have in the daemon.json. I don't think you need to do anything with it when running docker inside the jail. I know I haven't touched that file myself since switching.

I think you can also bind mount the directory where docker stores the images to a directory on the host. That way when you recreate a jail all the images are still downloaded. But since you also need to reinstall docker in this fresh jail perhaps that won't work the way I think/hope it does.

@Talung
Copy link

Talung commented Mar 1, 2023

Essentialy my last daemon.json was

{
  "data-root": "/mnt/pond/dockerset",
  "storage-driver": "overlay2",
  "exec-opts": [
    "native.cgroupdriver=cgroupfs"
  ],
  "runtimes": {
    "nvidia": {
      "path": "/usr/bin/nvidia-container-runtime",
      "runtimeArgs": []
      }
    }
}

But, as you mention with the bind mounts, if I add that dockerset, then it would make the jail extremely thin. Meaning the only thing I would need to do when creating it is a small script to install docker and setup the various files. That should be easy enough. Will be trying that soon with the nvidia changes and seeing if I can get that working. Got an old GTX 1070 in there.

Btw, I take it the quick/correct way to remove a jail is just to remove the folder after it is stopped?

EDIT: Interestingly enough this is what TrueNAS has changed the daemon.json file to:

{
	"data-root": "/mnt/pond/ix-applications/docker", 
        "exec-opts": ["native.cgroupdriver=cgroupfs"], 
	"iptables": false, 
	"bridge": "none", 
	"storage-driver": "overlay2"
}

No mention of nvidia in there.

@Jip-Hop
Copy link
Author

Jip-Hop commented Mar 1, 2023

Yes, you can just stop the jail and then remove the corresponding directory from the jails directory. I'd add a sleep of 1 second in between those 2 commands. Noticed the rm would fail because some files were not unmounted yet immediately after stopping the jail with machinectl stop.

@ZestyChicken
Copy link

2 questions for you guys - can you pull your TrueNAS Scale users into the jail and work with consistent users between the jail and Scale host?

For example, I have an apps user/group in Scale which has ownership of my media files (set up for TrueCharts). It looks like there is a flag -u that may do that but the language is confusing.

Also, if I wanted to expose port 80 & 443 for traefik, I know I can create an alias for my primary ip address but would this IP need to be attached to the jail via host or bridge networking? I set up a bridge but was unable to deploy traefik presumedly because it was complicting with the TrueNAS GUI.

@qudiqudi
Copy link

2 questions for you guys - can you pull your TrueNAS Scale users into the jail and work with consistent users between the jail and Scale host?

You have to translate your TN users into unique Users/Groups inside the jail. You can map them to the same UID/GID but I would advise against it to prevent permission issues.

Also, if I wanted to expose port 80 & 443 for traefik, I know I can create an alias for my primary ip address but would this IP need to be attached to the jail via host or bridge networking?

There is a networking section of the readme.md, read it carefully, as it gives concise yet direct instructions on how to do that. If you want to reverse proxy via traefik, your jail needs an IP address from your DHCP server. This is possible via a network bridge on the TN host.

@LimonChoms
Copy link

can amdgpu(like 5700xt,5600g...) run on jail?

@Jip-Hop
Copy link
Author

Jip-Hop commented Apr 28, 2023

I don't think so. As far as I know TrueNAS SCALE doesn't include drivers for AMD GPUs. But I could be wrong!

@LimonChoms
Copy link

I don't think so. As far as I know TrueNAS SCALE doesn't include drivers for AMD GPUs. But I could be wrong!

No,it has amdgpu drivers,it works on my jellyfin docker for hw-encoder very well.It's just that I don't know how to make it work in jail.

@Jip-Hop
Copy link
Author

Jip-Hop commented Apr 28, 2023

In that case I think it should be possible to use the GPU in the jail as well! But I don't know how and I don't have the time and hardware (AMD GPU) to figure this out. Perhaps you could draw inspiration form the nvidia GPU passhtrough issue?

@nguypaul
Copy link

nguypaul commented May 7, 2023

I just wanted to say thanks for this script. I finally migrated my 15 apps from Truecharts over to a jail. I'm using portainer and docker compose to manage everything and it is working nicely. Nvidia GPU passthrough took some effort but I finally got that working with Jellyfin and Nextcloud. Traefik is also working well as my reverse proxy.

I disabled k3s and now my CPU usage doesn't hover around 15% anymore. Very Happy so far.

@Jip-Hop
Copy link
Author

Jip-Hop commented May 7, 2023

Glad to hear that @nguypaul 😄👍

@worksmarter
Copy link

Really excited about this but I ran into a snag on my system. When prompted by the script I added the --network-bridge=br1 --resolv-conf=bind-host and the jail fails to boot - comes up with an error... My need is to setup portainer in the jail. Docker-compose installed without a problem, but I can't figure out how to make the network bridge work so when I install Portainer I can reach it.

Right now I am at the stage where the jail is installed and running; so is docker-compose, but I don't know exactly how I add the "--network-bridge=br1 --resolv-conf=bind-host" to the config file to bring up the bridge. Sorry, I am sure this is trivial, but I am not having any luck adding it in the "jlmkr.py" file. Is it possible you can assist me? I looked at the config file on my first attempt and failed trying to add that tidbit of code to it. It never brought up a bridge for portainer.

@nguypaul
Copy link

nguypaul commented May 8, 2023

When prompted by the script I added the --network-bridge=br1 --resolv-conf=bind-host and the jail fails to boot - comes up with an error...

I'm not sure if my scenario is the same as yours, but when creating the jail the only customization I add is the --bind='/mnt/pathtodata' to mount my shares.

The jail automatically has full access to the host network so I can reach portainer just by using the ip address of my host and the port configured for portainer. I can share my portainer compose file if you think that will be helpful.

@worksmarter
Copy link

Okay, hey thanks. Yes, I too set the flags to bind my mount points. (and the flags for a network bridge). I just can't get networking going properly and now I basically have no network connectivity. Following the instructions and setting up a bridge as per instructions is not working for me. Right now I am trying to get the networking running again, for I can't even ping google! Frustrating - I know this can't be so hard...

@Jip-Hop
Copy link
Author

Jip-Hop commented May 8, 2023

I assume you have been patient for the jail to be assigned an IP addresses via DHCP? For me (and others reported too) that it can take a while, up to 30 seconds I guess. If you leave the jail with bridge up for a bit and network still doesn't work then it's a different problem. But as @nguypaul mentions, a bridge is not required to use portainer in the jail. So unless you have a specific reason to go 'the hard way' I'd just use it with the default networking.

@worksmarter
Copy link

Thank you Sir and thank you for the wonderful script. I finally got everything talking to one another (Internet, apps). I am obviously doing something wrong with portainer. I never had an issue using the docker-compose truechart and pointing it at a docker-compose.yml file. I can't see how I would use that approach here. I am at a complete loss, which saddens me as I am sure this system seems to work swimmingly for everyone else. And sadly how to install and access portainer is not within the scope of this gist.

@worksmarter
Copy link

worksmarter commented May 8, 2023

Should there be an address in this? (Output from ./jlmkr.py list)
MACHINE CLASS SERVICE OS VERSION ADDRESSES
docker-compose container systemd-nspawn debian 11 -

@nguypaul
Copy link

nguypaul commented May 8, 2023

@worksmarter share your portainer compose file.

@worksmarter
Copy link

There is where it appears to be:
Run this with docker compose up -d and it comes right up as everyone said it would. I feel so stupid but it had to be the ports.

`version: '3'

services:
portainer:
image: portainer/portainer-ce:latest
container_name: portainer
restart: unless-stopped
security_opt:
- no-new-privileges:true
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./portainer-data:/data
ports:
- 9000:9000`

Wish I had come to that conclusion before posting. AND hasltleing around with bridging the networks, what a hassle that was. Thanks for your patience everyone. Great script JipHop!

@tprelog
Copy link

tprelog commented Jun 17, 2023

I just heard read the news 😞

Update: 15-6-2023. Looks like the systemd-container package has been removed since 22.12.3...

I haven't used your jailmaker script, but this still sucks.

@Talung
Copy link

Talung commented Jun 17, 2023

I just heard read the news 😞

Update: 15-6-2023. Looks like the systemd-container package has been removed since 22.12.3...

I haven't used your jailmaker script, but this still sucks.

wow... Good thing I am busy converting back to Proxmox for vm/container needs and will be running TrueNAS as a VM in that. For the little bit of VM's i was doing it just became too much hassle fighting Truenas imho. Now it is being relegated to ONLY a file server.

@aardvarkl
Copy link

Now that would be annoying as jailmakr works perfectly, doesn't have the crappy IX routing that IX has inflicted on K3S and is simpler.

I might not uprgade for a while

@Ixian
Copy link

Ixian commented Jun 18, 2023

I mean, by now we should all figure that Ix Systems is dead-set on SCALE being used their way or the highway, and non-commercial users are simply a pool of free beta testers for them, so if you hate how they handle apps - and it is dumb, no two ways about it - then best case use it as a simple, dumb fileserver, or leave it. Time to move on from the AIO idea.

@nader-eloshaiker
Copy link

You want to know what really doesn’t make sense about this, they are using K3S as the platform to scale your app server requirements . I don’t see many enterprises using that for their app servers. Also note that it is called TrueNAS and not TrueApp, they are shoe horning application enterprise server requirements into an enterprise file server.

@Ixian
Copy link

Ixian commented Jun 22, 2023

It only doesn't make sense because we're missing context. Likely it is as simple as: Ix Systems, being a for-profit business in a tough market (there's no money in storage hardware sales except at scale, so you have to differentiate with software these days), is trying to better define the space they are in so they can expand, and based on (presumably) their own internal market research concluded this is the way to go. Will it work or not? Does it make sense outside of Ix Systems? Who knows? It doesn't matter.

Folks like us are their field beta testers, more or less. Heck they aren't even subtle about that, their Enterprise marketing highlights how many Truenas (and SCALE) users there are, etc. We get a decent fileserver and whatever else they want to throw on top of it but let's not be under any illusion that they really care how any of us want to use the system. If we aren't paying for it then we are the product simple as that.

@qudiqudi
Copy link

I'd like to give a more positive notion into this discussion. Yes, iX, at the moment, is presumably trying to contain their user base inside their newly build ecosystem, which happen to be a catalogue of k8s apps. Nobody says that this is not gonna change in the future. It is just what they decided to do and it's their product, so that's the way it is. BUT, they have a over a decade long track record of changing their product according to what the community wants and needs. See i. e. the change from FreeBSD warden jails to iocage. Every time a "breaking" change was introduced, it lead to some kind of "backlash" in the Forums, later also on reddit. But over time everybody agreed that it was for the better. And they still have a huge list of stuff users want and I'm convinced they are looking into it. Though, at the end of the day we have the great pleasure of using their product for free and they still need to pay staff. So I'm pledging for this: we vote the according JIRA-Tickets with the features we want to see and we further voice our constructive criticism here, in the forums, on Discord and on (reddit maybe not anymore).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment