简体   繁体   English

GitLab CI docker 构建 - docker:未找到 - 退出代码 127

[英]GitLab CI docker build - docker: not found - exit code 127

I'm trying to create a CI/CD Pipeline for a simple java/maven project.我正在尝试为一个简单的 java/maven 项目创建一个 CI/CD 管道。 The runner that I'm using is a docker runner.我使用的跑步者是 docker 跑步者。
I'm using a dockerfile to create a container which installs maven/java/etc.. and in this container the program should be tested.我正在使用dockerfile创建一个安装 maven/java/etc 的容器。在这个容器中应该测试程序。

Sorry for the question but I am new to CI/CD Pipelines in GitLab.很抱歉这个问题,但我是 GitLab 中的 CI/CD 管道的新手。

GitHub works just fine have a look: https://github.com/ni920/CICD-Test GitHub 工作正常看看: https://github.com/ni920/CICD-Test

Thank you谢谢


Here are the CI logs这是 CI 日志

...
Executing "step_script" stage of the job script
 $ docker build --build-arg JAVA_VERSION=openjdk7
 /bin/sh: eval: line 95: docker: not found
Cleaning up file based variables
 ERROR: Job failed: exit code 127

Thats the .gitlab-ci.yml那是.gitlab-ci.yml


stages:
  - java7
# - java11
# - deploy


java7:
  stage: java7
  script:
      - docker build --build-arg JAVA_VERSION=openjdk7
 # tags:
 #   - docker

#java11:
#  stage: java11
#  script:
#    - docker build --build-arg JAVA_VERSION=openjdk11
#  tags:
#    - docker

Thats the dockerfile那就是dockerfile

# Pull base image.
FROM alpine as build

ARG MAVEN_VERSION=3.6.1
ARG USER_HOME_DIR="/root"
ARG JAVA_VERSION=openjdk7
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries

ENV HTTP_PROXY=#comment
ENV HTTPS_PROXY=#comment

# Install Java.
RUN apk --update --no-cache add JAVA_VERSION curl

RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
 && curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
 && tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
 && rm -f /tmp/apache-maven.tar.gz \
 && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn

ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"

# Define working directory.
WORKDIR /data

# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/default-jvm/

# Define default command.
CMD ["mvn", "--version"]



Running your pipelines using the Docker executor means that your jobs will run in a Docker container , but not that you will be able to execute docker commands.使用Docker执行器运行管道意味着您的作业将在Docker 容器中运行,但并不意味着您将能够执行docker命令。

If you need to run docker commands inside a GitLab CI job (read "inside a container" ) you will need Docker-in-Docker (often abbreviated DinD ).如果您需要在GitLab CI作业(阅读“容器内” )中运行docker命令(通常缩写为DinD )。 It is a vast topic on itself but you can get started with GitLab CI 's documentation: Use Docker to build Docker images它本身就是一个很大的话题,但您可以从GitLab CI的文档开始:使用 Docker 构建 Docker 图像


I always use DinD and have a minimal setup in my gitlab-ci.yml .我总是使用DinD并且在我的gitlab-ci.yml中有一个最小的设置。

Using a docker image as a default:默认使用docker映像:

image: docker:19.03.13

Define a default variable for TLS certificates:TLS证书定义一个默认变量:

variables:
    DOCKER_TLS_CERTDIR: "/certs"

Then use a docker image as a service to enable DinD :然后使用 docker 图像作为服务来启用DinD

services:
    -   name: docker:19.03.13-dind
        alias: docker

I wrote a few posts about using Docker-in-Docker on GitLab CI that you may find useful, but I still recommend to extensively read GitLab 's documentation before reading them.我写了几篇关于在GitLab CI上使用Docker-in-Docker的文章,您可能会觉得这些文章很有用,但我仍然建议您在阅读之前广泛阅读GitLab的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM