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 3,471 views

1 answer 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

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
1,000 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,440 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
3,392 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,460 points
3,698 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,929 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,020 points
2,718 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
732 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,813 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