My Digital Garden

Digital Ocean CLI

Digital Ocean CLI

The Digital Ocean CLI (Command Line Interface) allows users to manage their Digital Ocean resources from the command line.

To use it, first install the CLI on your system and then authenticate with your Digital Ocean account. Once authenticated, you can use the various commands to create, delete, and manage Droplets, images, volumes, and other resources.

You can also use the CLI to access the Digital Ocean API and perform more advanced tasks.


Installation instructions for multiple platforms are here

  1. Install doctl

  2. Create an API token, make a note

  3. Use the API token to grant account access to doctl:
    Pass in the token string when prompted by doctl auth init, and give this authentication context a name.

    doctl auth init --context <NAME>

    Authentication contexts let you switch between multiple authenticated accounts. You can repeat steps 2 and 3 to add other DigitalOcean accounts, then list and switch between authentication contexts:

    doctl auth list
    doctl auth switch --context <NAME>
  4. Validate doctl is working
    Check account details:

    doctl account get

    Test write access by creating...

    doctl compute droplet create --region lon1 --image ubuntu-22-04-x64 --size s-1vcpu-1gb <DROPLET-NAME>

    and then destroying a droplet (Use DROPLET-ID returned by previous step):

    doctl compute droplet delete <DROPLET-ID>
  5. (Optional) add environment variable for API Token
    Other tools (e.g. Terraform provider for Digital Ocean) may need to access the API Token, so create an environment variable DIGITALOCEAN_TOKEN and set it to the token value.


See the full Command Reference

See also