Question

How to delete a droplet after runnig my job

Hi, I have to run jobs for several hours, but after finishing them I want to destroy the droplet where they were being run. I have tried to accomplish this using doctl and an access token. The problem is that when I try to authenticate inside the droplet, running: doctl auth init --access-token $DO_TOKEN, I get the following error: Error: mkdir /root/.config: permission denied.

Any idea how to solve that? Or another way to destroy a droplet?

If it helps, I created the droplet using: doctl compute droplet create test --image ubuntu-20-04-x64 --size s-1vcpu-1gb --region nyc1 --ssh-keys $(key_md5)

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there @antoniogamiz10,

I recently wrote an answer to a similar question on how to delete a Droplet after running a specific task:

https://www.digitalocean.com/community/questions/create-droplet-to-run-single-task-then-destroy

It includes a short script as well.

Hope that this helps! Regards, Bobby

I’m actually not that familiar with doctl but I was able to find this open bug:

https://github.com/digitalocean/doctl/issues/591

tl;dr: Try creating the ~/.config directory before running doctl for the first time, like this:

mkdir -p ~/.config

The -p flag is handy for scripting as it will not error out if the directory already exists.

Hope this helps, let us know if you have any other questions - good luck!