Running CLI tools via container or VM

TheFluffyOne

Cadet
Joined
Feb 17, 2023
Messages
8
Since the installation of additional tools on the standard OS image is frowned upon, I'm looking at running commands from something like an Ubuntu container or VM. Mostly this is for file management where I'll want to run various tools that aren't included by default -- i.e. having the freedom to install any packages I need without worrying about breaking TrueNAS itself.

Whilst I've been using containers and VMs for a long old time, this is the first instance where I'm looking at using said container/VM to manage files on the machine that's hosting it! In the case of containers I've almost exclusively has long-running applications, whereas here there's a potential to just spin up the container directly into a shell when it's needed

Anybody already doing this? Any words of wisdom to share on config, what works, what doesn't?

Thanks!
 

MisterE2002

Patron
Joined
Sep 5, 2015
Messages
211
In the most ideal situation you would use a jail/lxc for toying around. It has the features of a VM and is lightweight like a container.
But this is not really available yet in SCALE.

So, the easiest way is to use a VM. Not sure about sharing data your NAS. Never used VMs in SCALE.

Personally i created my own Docker images. For example i have my own "jar" which i need to run with custom parameters. There are some caveats:
* A docker (main proces) is meant to run forever so i created a hacky "sleep"

Code:
#!/usr/bin/env bash
WAIT=180 && echo "Sleep for $WAIT seconds (one pod will be terminated - ix Bug)" && sleep ${WAIT}s
java -jar '/java_bin/myjar.jar' -f -C '/host_java_conf/
sleep infinity

* To supply custom input i put the input parameters at the host and than start the container

And you need to build to container with al tools packaged. In my example i created this Dockerfile

Code:
FROM alpine:3.17.1
ENV UID=1001
ENV GID=1001
ENV UID_NAME=app
ENV GID_NAME=app

RUN \
  echo "**** Install runtime packages ****" && \
  apk add -U --update --no-cache \
    bash \
    openjdk11 \
    tzdata && \
  addgroup --gid ${GID} ${GID_NAME} && \
  adduser --ingroup ${GID_NAME} --uid ${UID} --disabled-password ${UID_NAME} && \
  cp /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime


COPY --chown=${UID}:${GID} java_bin /java_bin
USER ${UID_NAME}:${GID_NAME}
CMD /java_bin/run.sh
 

MisterE2002

Patron
Joined
Sep 5, 2015
Messages
211
Also note they are removing Docker in the near future. Thus this is also not future proof :)
Seems you have to use the App "compose". So i have work to do.

There is also a guy who hacked jails into truenas. (search the forum). Not a fan of those hacks.
VM's are heavy and slow. Like to avoid them. A ticket for jails is alread filed by iX.

If you find other/better solutions let me know!
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
Top