Doctl Cli - Digitalocean

Digitalocean also has a CLI to manage the "DOCTL" infrastructure, which works similarly to AWS CLI, this tool allows us to avoid using the web interface of this provider.

Install Binary Tools

The first thing I have to do is download and install the binary, this for the current version 1.54.0:

1$ cd ~
2$ wget
3$ tar xf ~/doctl-1.54.0-linux-amd64.tar.gz
4$ sudo mv ~/doctl /usr/local/bin

Create Token API

Before using "doctl", you need to create a digitalocean API Token for your account, with read and write access from the Applications and API page in the control panel.

The token string is only shown once, so please copy and keep in a safe place.

Account Access with Token API and doctl

The Token API grants access to "doctl" for your digitalocean account. Pass the Token string when prompted, when executing the "doctl" command.

You can use multiple accounts, using different names, for this function the --context parameter allows it.

1$ doctl auth init --context <NOMBRE_CUENTA1>
2$ doctl auth init --context <NOMBRE_CUENTA2>
3$ doctl auth init --context <NOMBRE_CUENTA3>

All accounts can be listed with the following command:

1$ doctl auth list

To switch between the different existing accounts:

1$ doctl auth switch --context <NOMBRE_CUENTA_DISPONIBLE>

Examples of use

We can use "doctl" in different cases.

  • Account verify
1$ doctl account get
  • List Droplets
1$ doctl compute droplet list
  • Create Droplet
1$ doctl compute droplet create --region sfo2 --image ubuntu-18-04-x64 --size s-1vcpu-1gb <NOMBRE_DROPLET>
  • Delete Droplet
1$ doctl compute droplet delete <ID_DROPLET>