I see that ~/.dockercfg
has your login credentials, but it is your email and not your username. I see that running docker login
displays your username and prompts you to change it. But, you can you just get your username to put into a build script?
Display the username with:
docker info | sed '/Username:/!d;s/.* //'
Store it in a variable with:
username=$(docker info | sed '/Username:/!d;s/.* //');
echo $username
Note that if you have bash history expansion (set +H
) you will be unable to put double quotes around the command substitution (e.g. "$(cmd...)"
because !
gets replaced with your last command. Escaping is very tricky with these nested expansions and using it unquoted as shown above is more readable and works.