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!!
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.
Click below to sign up and get $100 of credit to try our products over 60 days!
There are a few ways that you can acomplish this using environment variables:
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:
You could also write a configuration file containing the token manually:
echo “access-token: $DO_TOKEN” > ~/.config/doctl/config.yaml
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