DigitalOcean Droplets are Linux-based virtual machines (VMs) that run on top of virtualized hardware. Each Droplet you create is a new server you can use, either standalone or as part of a larger, cloud-based infrastructure.
User data is arbitrary data, often a script, that you can supply to a Droplet during creation. [cloud-init](https://cloud-init.io/) is a tool that applies user data to automatically configure cloud servers like Droplets.
When you provide user data to a Droplet with cloud-init, cloud-init consumes the user data, which it can use to perform tasks as the root user during the Droplet’s first boot. This is helpful for automation setup for tasks like creating new users, customizing firewall rules, installing applications, and configuring SSH keys.
cloud-init accepts cloud-config
files or any script that can be interpreted by the Droplet, like a Bash script.
cloud-init is available on DigitalOcean’s latest Ubuntu and CentOS images. You can define user data for images that do not support cloud-init, but the user data is not consumed automatically on first boot.
You can provide user data to a Droplet during creation via the DigitalOcean Control Panel, the API, or doctl
, the CLI client.
To provide user data when creating a Droplet via the DigitalOcean Control Panel, on the Droplet creation page, above the Finalize Details section, click + Advanced Options. In the section that opens, check the box next to Add Initialization scripts. Add your user data in the box that appears.
To provide user data when creating a Droplet via the DigitalOcean API, use the user_data
field in the Droplet creation POST request.
To provide user data when creating a Droplet via doctl
, the DigitalOcean CLI, use the --user-data
or --user-data-file
flags when calling doctl compute droplet create
.
You cannot modify user data after a Droplet is created.
To see how a cloud-init file uses the provided user data, view the /var/log/cloud-init-output.log
file:
cat /var/log/cloud-init-output.log | grep userdata
The file logs output from cloud-init so you can view warnings, error messages, and debug information.
cloud-init has both reference documentation and examples to see which properties of your Droplet you can automatically configure upon deployment.