Index ¦ Archives  ¦ Atom  ¦ RSS

Docker Here and Now

I'm an avid user of software. Whenever I have an idea, a project, a problem, or a whim, I usually have to install some software to get it done. That might be something big and graphical like GIMP or Inkscape or Blender, but usually it's smaller software or packages.

Recently, it's been a few different npm/yarn CLI commands, as well as a couple Go packages. Most instructions lead me to install the language toolchain (node, go, python), their package manager (npm/yarn, go, pip/uv) and then use the package manager to install the package. I'd rather not clutter up my machine, so while I have uv installed, I'm avoiding installing everything else.

As a result, I've started using Docker containers with those tools installed instead. That way, the occasional docker system prune cleans up unused toolchains, something I have to do anyway.

However, I hate dealing with permissions, paths etc, so I have a very simple script:

docker-here

I put this in my ~/bin/, but again most instructions will say to put it in /usr/local/bin/ because they don't want to also explain modifying your PATH variable.

#!/usr/bin/env bash
IMAGE=${IMAGE:-"ubuntu:24.04"}
docker run -it --rm \
  -e USER="$(id -u)" \
  -e HOME=/workdir \
  -u="$(id -u)" \
  -v "$PWD:/workdir" \
  --workdir /workdir \
  ${IMAGE} "$@"

All it does is create and run a container with me as the user, mounts the current directory as /workdir and starts in that folder. Whenever I want to run yarn I can run:

IMAGE=node:23-alpine docker-here yarn build

Or for Go: IMAGE=golang:1.23-bookworm docker-here go build

What about Python, {other lang}, etc?

I default to using Python for my scripts, so I have pip and now uv installed so I just uv venv venv; . venv/bin/activate; uv pip install -r requirements.txt for Python projects. For Python and other languages, you can likely find a Docker image that has the tools you want pre-installed, and that's all you need. And if you can't find such an image, you can use a debian or ubuntu image (or whatever you prefer) and apt install your tool. Once you leave the container, the --rm flag tells it to clean up the container so you won't have too much cruft left over. You'll need to run docker system prune once in a while, however.

Bazel

And if you've seen my other posts, you may be able to deduce that for any large, multi-langugae project, I use Bazel to pull the toolchains and dependencies. However, I don't even install bazel. Instead, I only have devpod installed and use that to build a container that has bazelisk and everything else the project needs, then I use that container.

© Fahrzin Hemmati. Built using Pelican. Theme by Giulio Fidente on github.