gcloud emulator rapidly filling up all Docker disk space

Viewed 151

EDIT 4: I've opened up an issue for this: https://issuetracker.google.com/issues/219164388


I'm using the Google Cloud Run emulator (glcoud beta code dev), and it works fine...

...until after I've used it for a few days, it has consumed all of the hard disk space that I've allotted to Docker (60 GB!) and fails to run anymore.

I then manually force-clear Docker's disk space using docker system prune --all --force --volumes.

Is there a way to tell gcloud to automatically clear out all the files it has written when shutting down the emulator?

Maybe a flag I'm missing? Or maybe I'm shutting down the wrong way? I'm currently stopping the emulator by ctrl+C from the terminal.

EDIT 3: As pointed out in the answer below, what I need is the equivalent of the docker --rm, but for gcloud.


EDIT: In case it helps, I think I have an idea of what's causing the fill-up:

I'm using GCR to serve a webpage, and in my Dockerfile. Every time I make changes, the gcloud emulator rebuilds the container. I think that with each rebuild, it's re-copying all the assets (images, audio), which is why it eats up so much disk space.


EDIT 2: Docker shows glcoud-local-dev as in-use even after I've ctrl+C shut down the emulator from the command line.

1 Answers

As you said, you may use the following command to remove all unused containers, volumes, networks, and images at once:

docker system prune -a -f --volumes

If that isn't enough, one can start by removing operating containers:

docker rm -f $(docker ps -a -q) docker system prune -a -f --volumes

Using a different site with additional space is also a viable option for resolving this issue.

Currently, the best practice for this is to run the following command: docker system prune

Before you accept the consequences, take note of the output from this command:

WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all dangling images - all dangling build cache Are you sure you want to continue? [y/N]

To put it in another way, continuing to use this command is irreversible. Keep in mind that the recommended practice is to treat stopped containers as ephemeral, which means you should design your Docker job to avoid keeping them around. If you're not actively debugging your containers, you might wish to use the --rm flag at runtime.

According to gcloud beta code dev, it does not mention any flag yet that can prevent your main issue. Please consider that this command is currently in BETA and may change without notice. It was last updated on 2021-10-19.

This variant is also available: gcloud alpha code dev

Related