gpt4 book ai didi

docker 找不到 docker :dind + google/cloud-sdk

转载 作者:行者123 更新时间:2023-12-02 18:05:15 25 4
gpt4 key购买 nike

在 gitlab-ci 中运行以下 CI 脚本时出现错误 docker: command not found。此错误发生在部署阶段的 before_script 期间。

services:
- docker:dind

stages:
- build
- test
- deploy

before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

build:
stage: build
image: docker:latest
script:
- docker info
- docker version
- docker build --pull -t $SERVICE_NAME:$CI_COMMIT_REF_NAME .
- docker image list
- docker tag $SERVICE_NAME:$CI_COMMIT_REF_NAME $CI_REGISTRY_IMAGE/$SERVICE_NAME:$CI_COMMIT_REF_NAME
- docker push $CI_REGISTRY_IMAGE/$SERVICE_NAME:$CI_COMMIT_REF_NAME

test:
image: docker:latest
stage: test
script:
- docker pull $CI_REGISTRY_IMAGE/$SERVICE_NAME:$CI_COMMIT_REF_NAME
- docker image list
- docker run $CI_REGISTRY_IMAGE/$SERVICE_NAME:$CI_COMMIT_REF_NAME npm test

deploy:
image: google/cloud-sdk
stage: deploy
environment: Production
script:
- echo $DEPLOY_KEY_FILE_PRODUCTION > /tmp/GCLOUD_KEYFILE.json
- gcloud auth activate-service-account --key-file /tmp/GCLOUD_KEYFILE.json
- rm /tmp/GCLOUD_KEYFILE.json
- gcloud info
- gcloud components list
only:
- master

我有点困惑,因为我正在运行 docker-in-docker (docker:dind) 作为服务,所以 docker 命令应该可用于所有阶段(如果我理解的话)这是正确的),但显然不是。

是否与 google/cloud-sdk 交互?

最佳答案

您可能误解了services 的含义。来自doc ,

The services keyword defines just another docker image that is run during your job and is linked to the docker image that the image keyword defines.

您需要的是一个使用 dind 镜像并预装了 gcloud sdk 的自定义 docker 执行器。您可以使用此 Dockerfile 构建这样的图像:

FROM docker:latest

RUN apk add --no-cache \
bash \
build-base \
curl \
git \
libffi-dev \
openssh \
openssl-dev \
python \
py-pip \
python-dev

RUN pip install docker-compose fabric
RUN curl https://sdk.cloud.google.com | bash -s -- --disable-prompts

关于docker 找不到 docker :dind + google/cloud-sdk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43571787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com