brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker login --password-stdin keeps your password out of shell history

Docker
~/tips/tip-docker-login-password-stdin

cat ~/my_token.txt | docker login --username myname --password-stdin

Logs in to a registry with a password read from standard input, not typed in the command.

Typing a token straight after docker login -p is the lazy way, and it leaves the token in your shell history and in the process list. Docker has a better flag for scripts and for people like me who paste tokens around.

cat ~/my_token.txt | docker login --username myname --password-stdin

Docker reads the password from standard input. According to the Docker docs, that keeps it out of the shell’s history and out of log files. You can also pass - as the value of --password to get the same thing.

In a script or a CI job the token usually sits in a variable. Then printf does the job:

printf '%s' "$REGISTRY_TOKEN" | docker login ghcr.io -u myname --password-stdin

Without a registry name the login goes to Docker Hub. With one, it goes to that registry.

The caveat is where the login ends up. If you have not set up a credential store, Docker keeps your credentials in config.json in a base64-encoded form. Base64 is not encryption, so anyone who can read that file can read the token. The docs call this less secure than using a credential store. I’d use an access token with the least rights it needs, not the account password, so a leaked file costs less.

Further reading: docker login reference

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link