MongoDB Docker container: ERROR: Cannot write pid file to /tmp/tmp.aLmNg7ilAm: No space left on device

I had to delete old Docker images to free up space, here are the commands I used:

# remove all unused / orphaned images
echo -e  "Removing unused images..."
docker rmi -f $(docker images --no-trunc | grep "<none>" | awk "{print \$3}") 2>&1 | cat;
echo -e  "Done removing unused images"

# clean up stuff -> using these instructions https://lebkowski.name/docker-volumes/
echo -e  "Cleaning up old containers..."
docker ps --filter status=dead --filter status=exited -aq | xargs docker rm -v 2>&1 | cat;
echo -e  "Cleaning up old volumes..."
docker volume ls -qf dangling=true | xargs docker volume rm 2>&1 | cat;

We've experienced this problem recently while using docker-compose with mongo and a bunch of other services. There are two fixes which have worked for us.

  1. Clear down unused stuff
# close down all services
docker-compose down

# clear unused docker images
docker system prune

# press y
  1. Increase the image memory available to docker - this will depend on your installation of docker. On Mac, for example, it defaults to 64Gb and we doubled it to 128Gb via the UI.

We've had this problem in both Windows and Mac and the above fixed it.