![](/img/trans.png)
[英]gitlab ci error /bin/sh: eval: line 138: docker: not found
[英]Strange error docker in docker gitlab: /bin/sh: eval: line 120: docker-compose: not found
論壇,
我遇到了一個與以下 CICD 腳本相關的奇怪問題:
image: docker:stable
variables:
DOCKER_DRIVER: overlay2
CONTAINER_RELEASE_IMAGE_APP: $CI_REGISTRY_IMAGE/app:latest
CONTAINER_RELEASE_IMAGE_APP_DEV: $CI_REGISTRY_IMAGE/app_dev:latest
# from https://storage.googleapis.com/kubernetes-release/release/stable.txt
K8S_STABLE_VERSION_URL: https://storage.googleapis.com/kubernetes-release/release/v1.18.4/bin/linux/amd64/kubectl
.k8s:
services:
- name: docker:18.09.7-dind
command: ["--mtu=1410"]
variables:
DOCKER_HOST: tcp://localhost:2375
tags:
- kube-onpremise
##################
# ---- DEV ----- #
##################
build_dev:
stage: build
script:
# Login
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
#Try to pull image from container registry
- docker pull $CONTAINER_RELEASE_IMAGE_APP_DEV || true
#Build --pull Dockerfile (build --pull will pull latest version of any base image(s) - in this case python - instead of reusing whatever
#you already have tagged locally). tag it with $CONTAINER_RELEASE_IMAGE_APP_DEV.
#--cache-from is flag for other layers (app code and dependency). In this case we use the $CONTAINER_RELEASE_IMAGE_APP_DEV as cache.
- docker build -f Dockerfile --pull -t $CONTAINER_RELEASE_IMAGE_APP_DEV .
#--cache-from $CONTAINER_RELEASE_IMAGE_APP_DEV
#Push image back into container registry
- docker push $CONTAINER_RELEASE_IMAGE_APP_DEV
only:
changes:
- public/**/*
- Dockerfile
- requirements.txt
- .gitlab-ci.yml
refs:
- dev
deploy_dev:
stage: deploy
script:
#Login, this time with deploy credentials
- docker login -u $CI_DEPLOY_USER -p $CI_DEPLOY_PASSWORD $CI_REGISTRY
# - apk add --no-cache python py2-pip
# - pip install --no-cache-dir docker-compose
- ls -l
#Deploy application to docker swarm, --with-registry-auth indicates that registry authentication details (CI_DEPLOY...) Are send to swarm agents.
- docker stack deploy --compose-file=docker-compose.yml test_app --with-registry-auth
only:
- dev
當我創建一個新項目時,我總是從其他項目中復制/粘貼這個腳本 - 它總是工作正常。 我總是從一個簡單的管道開始(例如,這個管道構建/部署的 test_app 是一個簡單的 flask hello world 腳本)。 我有另一個項目具有完全相同的.gitlab-ci.yml
文件,它成功構建和部署,由以下 output 指示:
Login Succeeded
$ docker stack deploy --compose-file=docker-compose.yml clever_api --with-registry-auth
Updating service clever_api_uitschieterdetectie_api (id: pdcb2cwpg2xe6wfez0vk7sgap)
Job succeeded
但是,當我嘗試在當前項目上運行 CICD 腳本時,我不斷得到:
Login Succeeded
$ docker stack deploy --compose-file=docker-compose.yml test_app --with-registry-auth
open docker-compose.yml: no such file or directory
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1
我感覺在 gitlab 運行器上啟用docker-compose
時出了點問題。 但是,我不明白 - 成功和失敗項目的 docker-compose.yml 和 Dockerfile 幾乎相同。 我也在為這兩個項目使用相同的跑步者。 運行ls -l
顯示 docker-compose.yaml 實際上在 docker ZD0493DFC9D7551742B 的工作目錄中我認為問題一定與這個問題有關Using docker-compose in a GitLab CI 管道,但嘗試提出的解決方案(在我的 gitlab 腳本中注釋掉,以供參考)給了我另一個錯誤:
$ apk add --no-cache python py2-pip
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
py2-pip (missing):
required by: world[py2-pip]
python (missing):
required by: world[python]
Cleaning up file based variables
00:02
ERROR: Job failed: exit code 2
更新 1:我發現在另一個項目中使用了相同的運行器,並且它能夠運行 docker-compose。 所以它必須以某種方式安裝。 跑步者使用的基本圖像是alpine:latest
。
問題已解決:在我的存儲庫中,文件名為docker-compose.yaml
而不是docker-compose.yml
兩者都是有效的文件格式,所以我的編輯沒有抱怨。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.