Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Dockerized – Run CLI tools without installation (github.com/datastack-net)
78 points by datastack on March 10, 2022 | hide | past | favorite | 24 comments
Dockerized is like npx for unix tools: Run popular cli tools without installation.

Example:

    dockerized npm init
    dockerized python2 somescript.py
Run an older version of a tool:

    NODE_VERSION=15.0 dockerized node
Use cases:

- Maintaining multiple versions of an app

- Installing without polluting host machine

- Quickly run some commands you may not have installed

Features:

- intuitive use. Just the original command, but with 'dockerized' in front.

- dockerized apps can access the current directory and read/modify files, just like native apps.

- no need to know which docker image this package comes from.

- support for tools which don't have an official docker image.

- container cleaned up after use.

- ability to specify the version.

- version specification per directory (share exact versions with your team mates).

The inner workings are pretty simple, it's just a docker-compose file.

As expected with dockerization, there are limitations related to networking, and file persistence (outside current dir), but it can make life easy for simple scenarios.

Pull requests welcome!



Check out whalebrew for a similar idea but a bit more featureful like a registry of images and search, extensibility, etc: https://github.com/whalebrew/whalebrew

EnvCLI is another one that's been on my list to check out. It looks quite nice too: https://github.com/EnvCLI/EnvCLI


(MacOS Monterey 12.2.1)

$ whalebrew install whalebrew/wget Unable to find image 'whalebrew/wget' locally Using default tag: latest latest: Pulling from whalebrew/wget 540db60ca938: Pull complete fe215536b7c5: Pull complete Digest: sha256:dff6b84c2e317d4c1a6a81c55e6f91d46b73dc19713f53d06cf3a3b19b0c7815 Status: Downloaded newer image for whalebrew/wget:latest docker.io/whalebrew/wget:latest there's already an installation of wget, but there was an error loading the package, err: yaml: invalid trailing UTF-8 octet

$ whalebrew list COMMAND IMAGE



Thank you, Whalebrew seems like the tool I have been missing!

Edit: "Windows support is theoretically possible, but not implemented yet" :-(


I use NIX for this

  nix-shell -p go_1_17
Pops a native shell on my system with Go installed. Nothing else on my system is affected.


This will probably work better for things like compiler tools, or other tools that really require access to the entire filesystem, installed packages, and whatnot.


This thing mounts in my home directory. For the vast majority of people, that is already access to all files that matter.


Comma lets you run all Nix packages (more than 80000) quickly "without installation". It is basically a wrapper around `nix run` though. Honestly, `nix run` and `nix shell` help you become adventurous removing your fear of breaking things.

https://github.com/nix-community/comma


Cool. Does this work on Windows too?


The AWS CLI, at least, promotes their official Docker image with instructions in the docs.

https://docs.aws.amazon.com/cli/latest/userguide/install-cli...


Yeah, I used their official image also.

If all cli tools were available as officially supported docker images, 'dockerized' would probably not need to exist, other than just a bash function (and something else for windows).

Unfortunately it's not the case, and many tools only come in zipped binaries, or must be compiled.

An alternative approach would have been to make docker images for all cli tools, and publish them. But the burden of maintenance would be quite a bit higher, and it would still be unclear for users which images to use for each cli tool.


Reminds me a bit of what 0install was trying to accomplish [1]

[1]: https://docs.0install.net/basics/first-launch/


I feel like this use of containers is similar to how buildah works under the hood, except you are applying side effects to the host system.


This is great, looking forward to play about with it and see if we can get zero config tool chains setup


This is just a wrapper script that does something similar to `docker run -v $(pwd):$(pwd)`. I mean, I could create a script that simply adds a bash alias to another program like `alias ls="ls -la"`, but is it really that useful to announce it and act like it is unique, compared to something like toolbox or bubblewrap or firejail?


Indeed, it is just a wrapper script, but I think the value is not in the `docker run` script, but in the preconfigured images.

With a premade list of cli tools, you won't have to figure out which image to use, write your own Dockerfile if there is no official docker image, how to mount the current directory (try that on windows), which extra volumes to mount (for persistence of npx packages, or .aws credentials, for example), and the 'aliases' will be compatible with unix and windows too.

This tool seemed handy to me, as it was basically a packaged version of what I was already doing with many separate bash scripts. I haven't seen those tools you mentioned, but I'll have a look.


I don't see anything in the code which sets/handles the current uid/gid - how do you prevent every file created by a dockerized wrapped app being owned by root?


That sounds like an issue. This initial version is made on Windows, and although the commands are all unix-compatible, the unix file-permissions have slipped past, as on Windows docker runs as the current user.

Would this be easy to fix? Like, determining the current user id, and setting it when launching the command? Or would the host uid need to be mapped to the docker uid, which might be different for each image?


You can pass in the current user’s uid/gid as an environment variable check out linuxserver images for an example https://hub.docker.com/r/linuxserver/unifi-controller


It is usually better to use --user $(id -u):$(id -g) to do this. You don't really need to pass it as a variable for the most part.


The author needs to add this and then try if everything works as expected (like npm and pip and so on)


You have absolutely lost your mind


That's it. That happens when devs are leveling. At some point, when one finds about "patterns" or other cool feature, they need to put it everywhere, or rewrite everything to "go", or "rust", or "from perl". Unfortunately lots of them publish it. (yes, I've been writing my own php frameworks back then as well)


Haha (' ̄▽ ̄) Be sure to check my upcoming library that can concatenate strings!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: