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 26, 2018 in DevOps & Agile by stephen
• 340 points

edited Oct 12, 2018 by Kalgi 115 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+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 26, 2018 by Atul
• 10,170 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
• 14,040 points

Related Questions In DevOps & Agile

0 votes
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
• 6,480 points
28 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,250 points
52 views
+1 vote
2 answers

How do I run Apache server from Docker without mapping to a location?

If you're seeing a 500 error, that's ...READ MORE

answered Oct 18, 2018 in DevOps & Agile by lina
• 8,100 points
50 views
+1 vote
2 answers
+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
631 views
0 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
• 56,100 points
56 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 26, 2018 in DevOps & Agile by Atul
• 10,170 points
57 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,100 points

edited Oct 17, 2018 by lina 420 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.