Docker containers need to be stopped prior to being removed. As such the following commands should be run sequentially:

docker stop $(docker ps -a -q)

docker rm $(docker ps -a -q)