How to program and get the Digital Ocean ID of the current Droplet from within the Droplet

+5 votes

I am setting up monitoring and log aggregation on my AWS and Digital Ocean servers, and I want to be able to include a Droplet ID in the meta-data for my log messages from Digital Ocean.

On AWS there is a way to get the Instance ID from inside the instance: How to get the instance id from within an ec2 instance?

I am trying to find some similar in Digital Ocean so I can have a unique ID in my logs to identify a droplet.

I might have multiple web servers behind a load balancer, all answering to the same hostname and not looking for something like the hostname, since hostname can be set to anything in /etc/hostname.

I want a unique ID to help me find my Droplet in the API or web console, and I want to be able to get it from a shell script running on the Droplet.

Mar 27, 2018 in DevOps & Agile by stephen
• 340 points

edited Oct 12, 2018 by Kalgi 2,796 views

2 answers to this question.

+2 votes
Best answer

You can run curl http://169.254.169.254/metadata/v1/id within the droplet, that will get you the ID of the droplet. If you want to use it in a shell script, you can do something like this:

#!/bin/sh
droplet_id=$(http://169.254.169.254/metadata/v1/id)
echo "droplet id: $droplet_id"
# use $droplet_id in your script whenever you need to identify the droplet
...
answered Mar 27, 2018 by Atul
• 10,240 points

selected Oct 12, 2018 by Omkar
+1 vote

In account panel, you can find your droplets list. Click in the link to open droplet page and then check it URL. It should be something like this: https://cloud.digitalocean.com/droplets/XXXXX Where XXXXX is your droplet ID.

answered Oct 12, 2018 by Hannah
• 18,570 points

Related Questions In DevOps & Agile

+1 vote
1 answer

How do I get a Docker container's IP address from the host?

Save your docker image as a tar ...READ MORE

answered Aug 29, 2018 in DevOps & Agile by shubham
• 7,340 points
717 views
0 votes
1 answer

How to fix the misconfiguration of DNS for python app?

Based on what you have mentioned in ...READ MORE

answered Dec 12, 2018 in DevOps & Agile by Damon Salvatore
• 5,980 points
1,207 views
–1 vote
1 answer

How to Install and configure puppet agent on the slave node (Job 1)

Hey @Kavitha, where do u want to ...READ MORE

answered Feb 25, 2020 in DevOps & Agile by Sirajul
• 59,230 points
2,749 views
0 votes
1 answer

How to get the file count in amazon bucket linux cli

Hi@Shahzeb, You can do this task using the ...READ MORE

answered Apr 27, 2020 in DevOps & Agile by MD
• 95,440 points
3,282 views
+5 votes
7 answers

Docker swarm vs kubernetes

Swarm is easy handling while kn8 is ...READ MORE

answered Aug 27, 2018 in Docker by Mahesh Ajmeria
3,045 views
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,090 points
2,426 views
0 votes
1 answer

How do I use Devops with Xamarin and hockeyapp

It would be better if you use ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by Atul
• 10,240 points
500 views
+3 votes
4 answers

Unable to build docker image

It looks like the dev dependencies were ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points

edited Oct 17, 2018 by lina 5,389 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP