• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H07-Dec-2021-206173

cmd/doctl/H07-Dec-2021-269

commands/H07-Dec-2021-27,92221,407

do/H07-Dec-2021-10,4897,318

doc/adr/H07-Dec-2021-2010

dockerfiles/H07-Dec-2021-8068

integration/H07-Dec-2021-17,31714,868

pkg/H07-Dec-2021-485371

pluginhost/H07-Dec-2021-7443

scripts/H07-Dec-2021-565380

snap/H07-Dec-2021-8372

vendor/H03-May-2022-883,755720,304

.gitignoreH A D07-Dec-2021241 2924

.goreleaser.ymlH A D07-Dec-20211.1 KiB5446

.whitesourceH A D07-Dec-2021138 88

CHANGELOG.mdH A D07-Dec-202111 KiB330234

CONTRIBUTING.mdH A D07-Dec-202111.4 KiB278200

DockerfileH A D07-Dec-2021634 3626

Dockerfile.goreleaserH A D07-Dec-2021203 1611

MakefileH A D07-Dec-20215.6 KiB242194

README.mdH A D07-Dec-202117 KiB426297

args.goH A D07-Dec-202116.6 KiB408178

args_short.goH A D07-Dec-2021678 204

doit.goH A D07-Dec-202113.7 KiB510352

doit_test.goH A D07-Dec-20214 KiB156115

errors.goH A D07-Dec-20211.4 KiB4922

errors_test.goH A D07-Dec-2021822 269

go.modH A D07-Dec-20213.8 KiB8884

go.sumH A D07-Dec-202182.2 KiB852851

recorder.goH A D07-Dec-20211.5 KiB5835

util.goH A D07-Dec-20211.2 KiB4922

util_test.goH A D07-Dec-2021786 2911

README.md

1<h1 align="center">doctl</h1>
2
3<p align="center">
4  <img width="200" height="170" src="https://api-engineering.nyc3.cdn.digitaloceanspaces.com/doctl-mascot.png" alt="The doctl mascot." />
5</p>
6
7<p align="center">
8  <a href="https://travis-ci.org/digitalocean/doctl">
9    <img src="https://travis-ci.org/digitalocean/doctl.svg?branch=main" alt="Build Status" />
10  </a>
11  <a href="https://godoc.org/github.com/digitalocean/doctl">
12    <img src="https://godoc.org/github.com/digitalocean/doctl?status.svg" alt="GoDoc" />
13  </a>
14  <a href="https://goreportcard.com/report/github.com/digitalocean/doctl">
15    <img src="https://goreportcard.com/badge/github.com/digitalocean/doctl" alt="Go Report Card" />
16  </a>
17</p>
18
19```
20doctl is a command-line interface (CLI) for the DigitalOcean API.
21
22Usage:
23  doctl [command]
24
25Available Commands:
26  1-click         Display commands that pertain to 1-click applications
27  account         Display commands that retrieve account details
28  apps            Display commands for working with apps
29  auth            Display commands for authenticating doctl with an account
30  balance         Display commands for retrieving your account balance
31  billing-history Display commands for retrieving your billing history
32  completion      Modify your shell so doctl commands autocomplete with TAB
33  compute         Display commands that manage infrastructure
34  databases       Display commands that manage databases
35  help            Help about any command
36  invoice         Display commands for retrieving invoices for your account
37  kubernetes      Displays commands to manage Kubernetes clusters and configurations
38  monitoring      [Beta] Display commands to manage monitoring
39  projects        Manage projects and assign resources to them
40  registry        Display commands for working with container registries
41  version         Show the current version
42  vpcs            Display commands that manage VPCs
43
44Flags:
45  -t, --access-token string   API V2 access token
46  -u, --api-url string        Override default API endpoint
47  -c, --config string         Specify a custom config file (default "$HOME/.config/doctl/config.yaml")
48      --context string        Specify a custom authentication context name
49  -h, --help                  help for doctl
50  -o, --output string         Desired output format [text|json] (default "text")
51      --trace                 Show a log of network activity while performing a command
52  -v, --verbose               Enable verbose output
53
54Use "doctl [command] --help" for more information about a command.
55```
56
57See the [full reference documentation](https://www.digitalocean.com/docs/apis-clis/doctl/reference/) for information about each available command.
58
59- [Installing `doctl`](#installing-doctl)
60  - [Using a Package Manager (Preferred)](#using-a-package-manager-preferred)
61    - [MacOS](#macos)
62    - [Snap supported OS](#snap-supported-os)
63      - [Use with `kubectl`](#use-with-kubectl)
64      - [Using `doctl compute ssh`](#using-doctl-compute-ssh)
65      - [Use with Docker](#use-with-docker)
66    - [Arch Linux](#arch-linux)
67    - [Fedora](#fedora)
68    - [Nix supported OS](#nix-supported-os)
69  - [Docker Hub](#docker-hub)
70  - [Downloading a Release from GitHub](#downloading-a-release-from-github)
71  - [Building with Docker](#building-with-docker)
72  - [Building the Development Version from Source](#building-the-development-version-from-source)
73  - [Dependencies](#dependencies)
74- [Authenticating with DigitalOcean](#authenticating-with-digitalocean)
75  - [Logging into multiple DigitalOcean accounts](#logging-into-multiple-digitalocean-accounts)
76- [Configuring Default Values](#configuring-default-values)
77  - [Environment Variables](#environment-variables)
78- [Enabling Shell Auto-Completion](#enabling-shell-auto-completion)
79  - [Linux Auto Completion](#linux-auto-completion)
80  - [MacOS](#macos-1)
81- [Uninstalling `doctl`](#uninstalling-doctl)
82  - [Using a Package Manager](#using-a-package-manager)
83    - [MacOS Uninstall](#macos-uninstall)
84- [Examples](#examples)
85- [Tutorials](#tutorials)
86
87
88## Installing `doctl`
89
90### Using a Package Manager (Preferred)
91
92A package manager allows you to install and keep up with new `doctl` versions using only a few commands.
93Our community distributes `doctl` via a growing set of package managers in addition to the officially
94supported set listed below; chances are good a solution exists for your platform.
95
96#### MacOS
97
98Use [Homebrew](https://brew.sh/) to install `doctl` on macOS:
99
100```
101brew install doctl
102```
103
104`doctl` is also available via [MacPorts](https://www.macports.org/ports.php?by=name&substr=doctl). Note that
105the port is community maintained and may not be on the latest version.
106
107#### Snap supported OS
108
109Use [Snap](https://snapcraft.io/) on [Snap-supported](https://snapcraft.io/docs/core/install) systems to
110install `doctl`:
111
112```
113sudo snap install doctl
114```
115
116##### Use with `kubectl`
117
118Using `kubectl` requires the `kube-config` personal-files connection for `doctl`:
119
120    sudo snap connect doctl:kube-config
121
122##### Using `doctl compute ssh`
123
124Using `doctl compute ssh` requires the core [ssh-keys interface](https://docs.snapcraft.io/ssh-keys-interface):
125
126    sudo snap connect doctl:ssh-keys :ssh-keys
127
128##### Use with Docker
129
130Using `doctl registry login` requires the `dot-docker` personal-files connection for `doctl`:
131
132    sudo snap connect doctl:dot-docker
133
134This allows `doctl` to add DigitalOcean container registry credentials to your Docker configuration file.
135
136#### Arch Linux
137
138`doctl` is available in the official Arch Linux repository:
139
140    sudo pacman -S doctl
141
142As an alternative, you can install it from the [AUR](https://aur.archlinux.org/packages/doctl-bin/).
143
144#### Fedora
145
146`doctl` is available in the official Fedora repository:
147
148    sudo dnf install doctl
149
150#### Nix supported OS
151
152Users of NixOS or other [supported
153platforms](https://nixos.org/nixpkgs/) may install ```doctl``` from
154[Nixpkgs](https://nixos.org/nixos/packages.html#doctl). Please note
155this package is also community maintained and may not be on the latest
156version.
157
158### Docker Hub
159
160Containers for each release are available under the `digitalocean`
161organization on [Docker Hub](https://hub.docker.com/r/digitalocean/doctl).
162Links to the containers are available in the GitHub releases.
163
164### Downloading a Release from GitHub
165
166Visit the [Releases
167page](https://github.com/digitalocean/doctl/releases) for the
168[`doctl` GitHub project](https://github.com/digitalocean/doctl), and find the
169appropriate archive for your operating system and architecture.
170Download the archive from your browser or copy its URL and
171retrieve it to your home directory with `wget` or `curl`.
172
173For example, with `wget`:
174
175```
176cd ~
177wget https://github.com/digitalocean/doctl/releases/download/v<version>/doctl-<version>-linux-amd64.tar.gz
178```
179
180Or with `curl`:
181
182```
183cd ~
184curl -OL https://github.com/digitalocean/doctl/releases/download/v<version>/doctl-<version>-linux-amd64.tar.gz
185```
186
187Extract the binary:
188
189```
190tar xf ~/doctl-<version>-linux-amd64.tar.gz
191```
192
193Or download and extract with this oneliner:
194```
195curl -sL https://github.com/digitalocean/doctl/releases/download/v<version>/doctl-<version>-linux-amd64.tar.gz | tar -xzv
196```
197
198where `<version>` is the full semantic version, e.g., `1.17.0`.
199
200On Windows systems, you should be able to double-click the zip archive to extract the `doctl` executable.
201
202Move the `doctl` binary to somewhere in your path. For example, on GNU/Linux and OS X systems:
203
204```
205sudo mv ~/doctl /usr/local/bin
206```
207
208Windows users can follow [How to: Add Tool Locations to the PATH Environment Variable](https://msdn.microsoft.com/en-us/library/office/ee537574(v=office.14).aspx) in order to add `doctl` to their `PATH`.
209
210### Building with Docker
211
212If you have
213[Docker](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04)
214configured, you can build a local Docker image using `doctl`'s
215[Dockerfile](https://github.com/digitalocean/doctl/blob/main/Dockerfile)
216and run `doctl` within a container.
217
218```
219docker build --tag=doctl .
220```
221
222Then you can run it within a container.
223
224```
225docker run --rm --interactive --tty --env=DIGITALOCEAN_ACCESS_TOKEN="your_DO_token" doctl any_doctl_command
226```
227
228### Building the Development Version from Source
229
230If you have a [Go environment](https://www.digitalocean.com/community/tutorials/how-to-install-go-1-6-on-ubuntu-16-04)
231configured, you can install the development version of `doctl` from
232the command line.
233
234```
235go install github.com/digitalocean/doctl/cmd/doctl@latest
236```
237
238While the development version is a good way to take a peek at
239`doctl`'s latest features before they get released, be aware that it
240may have bugs. Officially released versions will generally be more
241stable.
242
243### Dependencies
244
245`doctl` uses Go modules with vendoring.
246
247## Authenticating with DigitalOcean
248
249To use `doctl`, you need to authenticate with DigitalOcean by providing an access token, which can be created from the [Applications & API](https://cloud.digitalocean.com/account/api/tokens) section of the Control Panel. You can learn how to generate a token by following the [DigitalOcean API guide](https://www.digitalocean.com/community/tutorials/how-to-use-the-digitalocean-api-v2).
250
251Docker users will have to use the `DIGITALOCEAN_ACCESS_TOKEN` environmental variable to authenticate, as explained in the Installation section of this document.
252
253If you're not using Docker to run `doctl`, authenticate with the `auth init` command.
254
255```
256doctl auth init
257```
258
259You will be prompted to enter the DigitalOcean access token that you generated in the DigitalOcean control panel.
260
261```
262DigitalOcean access token: your_DO_token
263```
264
265After entering your token, you will receive confirmation that the credentials were accepted. If the token doesn't validate, make sure you copied and pasted it correctly.
266
267```
268Validating token: OK
269```
270
271This will create the necessary directory structure and configuration file to store your credentials.
272
273### Logging into multiple DigitalOcean accounts
274
275`doctl` allows you to log in to multiple DigitalOcean accounts at the same time and easily switch between them with the use of authentication contexts.
276
277By default, a context named `default` is used. To create a new context, run `doctl auth init --context <new-context-name>`. You may also pass the new context's name using the `DIGITALOCEAN_CONTEXT` [environment variable](#environment-variables). You will be prompted for your API access token which will be associated with the new context.
278
279To use a non-default context, pass the context name to any `doctl` command. For example:
280
281```
282doctl compute droplet list --context <new-context-name>
283```
284
285To set a new default context, run `doctl auth switch --context <new-context-name>`. This command will save the current context to the config file and use it for all commands by default if a context is not specified.
286
287The `--access-token` flag or `DIGITALOCEAN_ACCESS_TOKEN` [environment variable](#environment-variables) are acknowledged only if the `default` context is used. Otherwise, they will have no effect on what API access token is used. To temporarily override the access token if a different context is set as default, use `doctl --context default --access-token your_DO_token ...`.
288
289## Configuring Default Values
290
291The `doctl` configuration file is used to store your API Access Token as well as the defaults for command flags. If you find yourself using certain flags frequently, you can change their default values to avoid typing them every time. This can be useful when, for example, you want to change the username or port used for SSH.
292
293On OS X, `doctl` saves its configuration as `${HOME}/Library/Application Support/doctl/config.yaml`. The `${HOME}/Library/Application Support/doctl/` directory will be created once you run `doctl auth init`.
294
295On Linux, `doctl` saves its configuration as `${XDG_CONFIG_HOME}/doctl/config.yaml` if the `${XDG_CONFIG_HOME}` environmental variable is set, or `~/.config/doctl/config.yaml` if it is not. On Windows, the config file location is `%APPDATA%\doctl\config.yaml`.
296
297The configuration file is automatically created and populated with default properties when you authenticate with `doctl` for the first time. The typical format for a property is `category.command.sub-command.flag: value`. For example, the property for the `force` flag with tag deletion is `tag.delete.force`.
298
299To change the default SSH user used when connecting to a Droplet with `doctl`, look for the `compute.ssh.ssh-user` property and change the value after the colon. In this example, we changed it to the username **sammy**.
300
301```
302. . .
303compute.ssh.ssh-user: sammy
304. . .
305```
306
307Save and close the file. The next time you use `doctl`, the new default values you set will be in effect. In this example, that means that it will SSH as the **sammy** user (instead of the default **root** user) next time you log into a Droplet.
308
309### Environment variables
310
311In addition to specifying configuration using `config.yaml` file or program arguments, it is also possible to override values just for the given session with environment variables:
312
313```
314# Use instead of --context argument
315DIGITALOCEAN_CONTEXT=my-context doctl auth list
316```
317
318```
319# Use instead of --access-token argument
320DIGITALOCEAN_ACCESS_TOKEN=my-do-token doctl
321```
322
323## Enabling Shell Auto-Completion
324
325`doctl` also has auto-completion support. It can be set up so that if you partially type a command and then press `TAB`, the rest of the command is automatically filled in. For example, if you type `doctl comp<TAB><TAB> drop<TAB><TAB>` with auto-completion enabled, you'll see `doctl compute droplet` appear on your command prompt.
326
327**Note:** Shell auto-completion is not available for Windows users.
328
329How you enable auto-completion depends on which operating system you're using. If you installed `doctl` via Homebrew, auto-completion is activated automatically, though you may need to configure your local environment to enable it.
330
331`doctl` can generate an auto-completion script with the `doctl completion your_shell_here` command. Valid arguments for the shell are Bash (`bash`), ZSH (`zsh`), and fish (`fish`). By default, the script will be printed to the command line output.  For more usage examples for the `completion` command, use `doctl completion --help`.
332
333### Linux Auto Completion
334
335The most common way to use the `completion` command is by adding a line to your local profile configuration. At the end of your `~/.profile` file, add this line:
336
337```
338source <(doctl completion your_shell_here)
339```
340
341Then refresh your profile.
342
343```
344source ~/.profile
345```
346
347### MacOS
348
349macOS users will have to install the `bash-completion` framework to use the auto-completion feature.
350
351```
352brew install bash-completion
353```
354
355After it's installed, load `bash_completion` by adding the following line to your `.profile` or `.bashrc`/`.zshrc` file.
356
357```
358source $(brew --prefix)/etc/bash_completion
359```
360
361Then refresh your profile using the appropriate command for the bash configurations file.
362
363```
364source ~/.profile
365source ~/.bashrc
366source ~/.zshrc
367```
368
369
370## Uninstalling `doctl`
371
372### Using a Package Manager
373
374#### MacOS Uninstall
375
376Use [Homebrew](https://brew.sh/) to uninstall all current and previous versions of the `doctl` formula on macOS:
377
378```
379brew uninstall -f doctl
380```
381
382To completely remove the configuration, also remove the following directory:
383
384```
385rm -rf "$HOME/Library/Application Support/doctl"
386```
387
388
389## Examples
390
391`doctl` is able to interact with all of your DigitalOcean resources. Below are a few common usage examples. To learn more about the features available, see [the full tutorial on the DigitalOcean community site](https://www.digitalocean.com/community/tutorials/how-to-use-doctl-the-official-digitalocean-command-line-client).
392
393* List all Droplets on your account:
394```
395doctl compute droplet list
396```
397* Create a Droplet:
398```
399doctl compute droplet create <name> --region <region-slug> --image <image-slug> --size <size-slug>
400```
401* Assign a Floating IP to a Droplet:
402```
403doctl compute floating-ip-action assign <ip-addr> <droplet-id>
404```
405* Create a new A record for an existing domain:
406```
407doctl compute domain records create --record-type A --record-name www --record-data <ip-addr> <domain-name>
408```
409
410`doctl` also simplifies actions without an API endpoint. For instance, it allows you to SSH to your Droplet by name:
411```
412doctl compute ssh <droplet-name>
413```
414
415By default, it assumes you are using the `root` user. If you want to SSH as a specific user, you can do that as well:
416```
417doctl compute ssh <user>@<droplet-name>
418```
419
420## Tutorials
421
422* [How To Use Doctl, the Official DigitalOcean Command-Line Client](https://www.digitalocean.com/community/tutorials/how-to-use-doctl-the-official-digitalocean-command-line-client)
423* [How To Work with DigitalOcean Load Balancers Using Doctl](https://www.digitalocean.com/community/tutorials/how-to-work-with-digitalocean-load-balancers-using-doctl)
424* [How To Secure Web Server Infrastructure With DigitalOcean Cloud Firewalls Using Doctl](https://www.digitalocean.com/community/tutorials/how-to-secure-web-server-infrastructure-with-digitalocean-cloud-firewalls-using-doctl)
425* [How To Work with DigitalOcean Block Storage Using Doctl](https://www.digitalocean.com/community/tutorials/how-to-work-with-digitalocean-block-storage-using-doctl)
426