Report this

What is the reason for this report?

How to authorize doctl in a script

Posted on February 1, 2021

Linux box 18.04, starts a droplet using images stored in a DO registry. I am creating the droplet, updating it, then copying all my assets into it ( including my docker-compose.YAML and everything needed to start the app). ( current end goal is to see my API at an address/port. I can’t pull my images out of the registry ( yet ) without installing doctl, authorizing it ( which includes pasting my API key at a prompt ) then logging into the machine, then I can run my docker-compose up, and everything goes as planned. I want to automate the entire process. My root image is alpine, I would rather not install bash, but if it helps this problem go away I will LOL. Any advice is appreciated!!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

There are a few ways that you can acomplish this using environment variables:

  1. If you pass the --access-token flag when configuring auth. The command will run without needing user input:

    doctl auth init --access-token $DO_TOKEN

Note that this will print the token to STOUT. So if you are logging the script, you might want to redirect that so your token can not be viewed in logs:

doctl auth init --access-token $DO_TOKEN> /dev/null
  1. You could also write a configuration file containing the token manually:

    echo “access-token: $DO_TOKEN” > ~/.config/doctl/config.yaml

  2. The --access-token flag works with all commands, you could just always pass it when using doctl:

    doctl compute droplet create
    –image ubuntu-20-04-x64
    –size s-1vcpu-1gb
    –region nyc1
    –access-token $DO_TOKEN example.com

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.