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 :

  • Intermittent Connection Errors for Docker Swarm Services
  • Running tests with Docker and Jenkins - Test Result
  • Docker Port Forwarding, Downloading Empty Files
  • How to change the 'Registry' value which shows from 'docker info'
  • ansible-docker invalid container.yml
  • How to connect jenkins to docker?
  • 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 !

  • nginx 403 Forbidden error
  • Connect to RPC Server in Docker
  • Load generation for a Docker registry
  • “The output of `ssh-add -l` doesn't contain 'RSA'. Start the agent, add your keys?” in Docker
  • apache-spark startup error on alpine linux docker
  • Docker Share Volume and edit files
  • 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.