Cannot remove all containers in a row

I started yesterday to use Docker and I unfortunately created a ton of containers.
Now I want to delete all of them. It would be really boring to delete them one by one because I have like 45 containers with no tag.
I found that I should use do delete all of them with one command something like :

sudo docker rm $(docker ps -q)

But when I try to use this command, it doesn’t work.
This is my output :

  • Expose host port for specific container interface
  • How to make pull public and push requiring login in docker registry v2?
  • Docker + MariaDB connection
  • boot2docker startup script to mount local shared folder with host
  • Windows Server 2016 Server Core set correct time with script
  • Unable to compile cpp via docker in Travis-CI: /usr/bin/ld: cannot open output file a.out: Permission denied
  • 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.25/containers/json: dial unix /var/run/docker.sock: connect: permission denied
    
    "docker kill" requires at least 1 argument(s).
    
    See 'docker kill --help'.
    
    Usage:  docker kill [OPTIONS] CONTAINER [CONTAINER...]
    
    Kill one or more running containers
    

    I understand that $(docker ps -q) doesn’t work well because there is a permission denied problem. But I don’t really know how I can solve this situation.

    Any help ?

    Thanks a lot !

  • What are the pros and cons of docker pull and docker build from Dockerfile?
  • Error connecting to python server running in boot2docker (centos container | Windows 7.1 host)
  • flannel tunnel solution in kubernetes
  • Containers are not linked with docker-compose version 2
  • Docker link container - environment variables not being displayed
  • error with dockerize [error 20] Not a directory
  • One Solution collect form web for “Cannot remove all containers in a row”

    I believe your docker daemon is not running. You can check it with sudo /etc/init.d/docker status

    If it’s running, maybe it is configured not to listen on /var/run/docker.sock. You can check in /etc/default/docker if any -H option is specified in DOCKER_OPTS.

    Related topic: after installing Docker you are prompted to add your user to the docker group. Run the command shown and restart your session to have the change taken into account, so you won’t need to run commands with sudoanymore

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.