You are not logged in.
Pages: 1
I am trying to get two commands run as an alias:
docker rm -f $(docker ps -a -q)
and
docker rmi -f $(docker images -q)
Thats why i added this to my zshrc:
alias dockerclean='docker rm -f $(docker ps -a -q) && docker rmi -f $(docker images -q)'
i also added:
alias sudo='sudo '
Because i read that my shell only looks at the first word for an alias.
But when in run "sudo dockerclean" i get this error:
sudo dockerclean
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.38/containers/json?all=1: dial unix /var/run/docker.sock: connect: permission denied
"docker rm" requires at least 1 argument.
See 'docker rm --help'.
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
Remove one or more containers
Last edited by philipW (2018-10-13 23:51:17)
Offline
Hi philipW, instead of sudoing the alias, alias sudo too:
alias dockerclean='sudo docker rm -f $(docker ps -a -q) && sudo docker rmi -f $(docker images -q)'
edit:
well, to explain a little, you have the 'alias sudo='sudo ' so you can 'sudo alias' that will expand but;
your situation is -
alias com='command && command'
so if you 'sudo alias' it will execute the first part as root.
But the command behind '&&' will not be expanded with sudo so you at least add that like
alias ='command && sudo command'
if you then 'sudo alias' it will execute both commands as sudo. Since there are 2 sudo's used in that alias, I would add them both, saves you typing 'sudo' everytime you execute the alias.
Clear enough I hope.
Last edited by qinohe (2018-10-12 13:03:27)
Offline
Hi qinohe,
Thanks for your reply i got it working now. It took me a while to find out i also had to put sudo in
$(docker ps -a -q)
and
$(docker images -q)'
Offline
Pages: 1