Pulling Docker Images Increase GCP Cost/Decreases Performance/Storage Immensely

Viewed 226

My main problem started first when I tried to deploy my docker image to gcp and received the error No Space Left On Device. After looking a while I found out that I had to delete the /var/lib/docker and pull the image again.

sudo umount /var/lib/docker/
    sudo systemctl stop docker
   sudo umount /var/lib/docker/
   sudo rm -rf /var/lib/docker/
    sudo systemctl restart  docker
    docker pull myImage
   docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v "$PWD:/rootfs/$PWD" -w="/rootfs/$PWD" docker/compose:1.26.0 up -d

When I want to get rid of the previous images/containers etc I run docker system prune -a but nothing seems to get pruned. And whenever I want to deploy another image same problem repeats.

As a result of this I have two terrible problems which become even worse for the last 3 days.

  1. Server become incredibly slow I am getting 502 Bad Gateaway (nginx, I am assuming server stopped responding). I am getting this message which asks me to increase the performance This instance has had high memory utilization recently. Consider switching to the machine type: custom (1 vCPU, 6.25 GB memory)
  2. Server costs increased a lot. First whenever I deployed a new image I was charged with 20-30 euros of GCP Storage egress between NA and EU which kept increasing. And for the last 3 days I am still charged for this even when I don't deploy anything. To give a comparison my estimated server total costs for a month increased from 150 euros to 925 euros.

I also tried to look at the inode usage before but I couldn't find the problem.

My docker images in total are around 400 MB. So it shouldn't make the disk full. My machine type is custom (1 vCPU, 4.75 GB memory)** and it has a 10 GB standard persistent disk

How can I fix these issues? I am especially concerned with the first question, but I think the answer to first question should help with second question as well.

Note: My VM is in Germany hence the cost for pulling the image from gcr.io (It pulls it from NA. I don't know how to pull it from Germany)

1 Answers

When using docker inside GCP, i would consider using the GCR (Google Container Registry).

Your 502, probably causes a container restarting duo to health checks forever. a problem which. So an infinitive restart loop. With an always pull policy.

Are you running docker on a VM? or are you using GKE(Google Kubernetes Engine)

Anyway, if you decide to use GCR, you never pay for image pulls... As long as your VM/GKE lives in the samen zone/region

You can choose to pull the images from a specific location using, another host:

eu.gcr.io instead of gcr.io

See: https://cloud.google.com/container-registry/docs/pushing-and-pulling

You probably also have to build it new on de eu.gcr.io

Google Container Registry is store on a Cloud Storage Bucket. You can just wipe the bucket, to be sure it's gone.

Check the storage browser from cloud console: https://console.cloud.google.com/storage/browser?project=PROJECT_ID_HERE

The bucket should look like this:
.artifacts.<project_id>.appspot.com

Please make sure to browse it first, as removing the bucket will wipe all your artifacts.

Related