Typing -e API_KEY=s3cret puts the secret in your shell history and in the process list. If you give only the name, Docker takes the value from your current environment.
export API_KEY="$(cat ~/.config/app/api_key)"
docker run --rm -e API_KEY example/app:1.0
Inside the container, API_KEY has the same value as in your shell. A name that is not set in your shell is simply left out, rather than being passed as an empty string.
The same works in an env file: a line with just API_KEY and no equals sign takes the value from the shell that runs docker run --env-file. In Compose, a list item - API_KEY under environment: does the same.
This keeps the value out of your history, not out of the container. Anyone who can run docker inspect on the container still sees it in plain text under Config.Env. For a real secret I would rather mount a file into the container. And a missing variable gives no warning, so the app starts without its key. Check the variable is set first, or make the app fail loudly when it is empty.
Further reading: docker container run: set environment variables