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.