I am trying to connect to a DigitalOcean container registry which I created using the web UI. I am following the QuickStart guide here:
https://www.digitalocean.com/docs/images/container-registry/quickstart/
I skipped the "Create a Registry" step because I think I have already created a
registry. Also, I have been using doctl
with Kubernetes and Terraform, so I'm
pretty sure I'm already authenticated with an API token as needed.
I had trouble getting doctl
to log in to the registry:
$ doctl registry login
Error: unable to find the Docker CLI binary. Make sure docker is installed
$ sudo doctl registry login 1 ↵
Error: mkdir /root/.config: permission denied
I tried running it with sudo
because I am on Ubuntu 19.10, and in order to
run docker
commands I need to run them as root. This didn't seem to work.
doctl
is installed via snap. I figured it might have something to do with
that, and after Googling, I came up with this error:
https://github.com/digitalocean/doctl/issues/709
Seems like @swetank01 had exactly the same issue as me! And posted a workaround here:
https://stackoverflow.com/questions/60221651/doctl-is-unable-to-find-docker-binary/60237742#60237742
It seems like this line is the issue:
https://github.com/digitalocean/doctl/blob/1b6d0b826a3d5af724a200f510be82d1ee01e2d0/commands/registry.go#L207
Doesn't seem to make sense because which docker
returns /usr/bin/docker and
/usr/bin is on the path (and putting it first with export PATH=/usr/bin:$PATH
doesn't help or change anything, either.) Weird.
Judging by the StackOverflow solution, it seems like the issue is Snap overriding PATH. Googling around, it seems like this does happen:
https://github.com/snapcore/snapd/wiki/Snap-Execution-Environment
"... The wrapper sets PATH, ..."
To double check that I'm right, I run:
$ snap run --shell doctl
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
<inside snap run> $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
<inside snap run> $ ls /usr/bin | grep docker
Although /usr/bin is on the $PATH, it seems to be some other version of /usr/bin that doesn't have the docker executable in it.
I was hoping that I can somehow modify the snap so it can access /usr/bin using
snap interfaces or connections or something, but after Googling around, it
doesn't seem to be possible. There's a docker
connection, but I think that
allows you to act like the Docker client, but won't actually give you access to
the docker
executable.
So it seems that the idea of getting access to the docker
executable is
doomed if you installed via Snap. Goodbye Snap doctl.
I get
the latest release of doctl (1.43), untar it, and move it to my
/usr/local/bin directory, which is on PATH. I run sudo snap remove doctl
.
I try to log in to Docker registry again, but get a permission error: "Got
permission denied while trying to connect to the Docker daemon". This makes
sense -- it tries to access the Docker daemon not as root. I try sudo
the
command, but now it doesn't work because doctl
isn't installed for root.
I modify my user permissions to allow running docker
client not-as-root.
Finally!
$ doctl registry login
Logging Docker in to registry.digitalocean.com
Login Succeeded
The subsequent docker tag
and docker push
commands to upload an image to
the registry work without issues.