[英]Permission denied on docker pull from Google Cloud Compute
因此,我使用 terraform 设置了一个最小的 Google Cloud Compute 实例,并希望在其上使用 docker 图像。 所需的图像被推送到同一项目中的工件存储库。
问题是无论我做什么,当尝试使用工件存储库中指定的拉取命令时,我得到:
sudo docker pull europe-west3-docker.pkg.dev/[project]/[repo]/[image]:latest
Error response from daemon:
Head "https://europe-west3-docker.pkg.dev/v2/[project]/[repo]/api/manifests/latest": denied:
Permission "artifactregistry.repositories.downloadArtifacts" denied on resource "projects/[project]/locations/europe-west3/repositories/[repo]" (or it may not exist)
我试过的:
gcloud auth configure-docker europe-west3-docker.pkg.dev
启用 docker auth 并使用gcloud auth list
调试使用的帐户。gcloud artifacts docker images list [repo]
访问存储库,也可以正常工作gcloud init
#
# INSTANCE
#
resource "google_compute_instance" "mono" {
name = "mono"
machine_type = "n1-standard-1"
allow_stopping_for_update = true # allows hard updating
service_account {
scopes = ["cloud-platform"]
}
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
network_interface {
network = "default"
access_config {
}
}
}
#
# REPO
#
resource "google_artifact_registry_repository" "repo" {
location = var.location
repository_id = var.project_name
format = "DOCKER"
}
在浪费了太多时间之后,我发现在将我的用户添加到 docker 组并因此在没有sudo
的情况下运行 docker 之后,它突然起作用了。
如此处所述: https://docs.docker.com/engine/install/linux-postinstall/
sudo groupadd docker
sudo usermod -aG docker $USER
# exit and login again via ssh
根据文档:
Note: If you normally run Docker commands on Linux with sudo, Docker looks for Artifact Registry credentials in /root/.docker/config.json instead of $HOME/.docker/config.json. 如果您想将 sudo 与 docker 命令一起使用,而不是使用 Docker 安全组,请改为使用 sudo gcloud auth configure-docker 配置凭据。
所以如果你使用 docker 和 sudo,你还需要运行
sudo gcloud auth configure-docker
我以为我已经尝试过了,但事实就是这样......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.