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