Borrowing Command-Line Tools
You want to peek into the quicknotes database with psql, test an HTTP endpoint with curl, or run a Python script, but you do not want to install any of those tools on your laptop. Containers make a tool something you can borrow for one command and hand back.
The rule
Borrow a tool for one command: --rm, mount what it needs, run, gone.
The pattern has three ingredients:
--rmdeletes the container as soon as the command finishes, so nothing piles up.-v "$PWD":/work -w /workmounts your current folder into the container and starts the command there, so the tool can see your files. Without a mount, it sees only the image's own files.-itgives the tool your keyboard and a terminal. Add it only for interactive programs, such as a shell orpsqlprompt.
# run a Python script from the current folder, no Python installed
docker run --rm -v "$PWD":/work -w /work python:3.12-slim python check.py
# call quicknotes from inside its network
docker run --rm --network notes-net curlimages/curl -s http://notes:5000/
# open an interactive psql prompt against the database
docker run --rm -it --network notes-net postgres:16 \
psql -h notes-db -U postgres -d quicknotesIn the last two lines, joining notes-net lets the borrowed tool reach containers by name, exactly like quicknotes does. And in the psql case you borrow only the client program from the postgres image; no second database starts, because your command replaces the image's default one.
The first run downloads the image; later runs reuse it from the cache, so the tool starts almost instantly.
The shortcut
Ask three questions before typing: Does it need my files? Add -v and -w. Does it need to reach other containers? Add --network. Does it need my keyboard? Add -it. Always add --rm.
The tool
Any small Linux image has
wc. Usealpine.
A common trap: running an interactive tool without -it. The program starts, finds no terminal, and exits immediately or appears frozen.
Drills
Answer fast — trust the rule.
What does --rm add to a one-off tool run?
A containerised linter reports "file not found" for your code. What is most likely missing?
You start docker run --rm postgres:16 psql -h notes-db -U postgres and it cannot find host notes-db. What should you add?
When do you need -it?
Remember
- Borrow a tool for one command:
--rm, mount what it needs, run, gone. - Shortcut: my files →
-v/-w; other containers →--network; my keyboard →-it. - Trap: forgetting the mount (file not found) or
-it(interactive tool quits or hangs).
