1
votes

I am trying to remove all the stopped container using the command sudo docker rm $(docker ps -a -q)

But its returns

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.35/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...] [flags]

Anyone can suggest me how can i remove all the stopped container.

1

1 Answers

4
votes

You ran sudo for your outer docker command, but not for the inner one. Your bash shell expands that inner command before the sudo runs. So you either need to run the entire command in a root shell, or call sudo each time, e.g.:

sudo docker rm $(sudo docker ps -a -q)

You could also add your user to the docker group to avoid the need to sudo every command.