Skip to content
Advertisement

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. The runner that I’m using is a docker runner.
I’m using a dockerfile to create a container which installs maven/java/etc.. and in this container the program should be tested.

Sorry for the question but I am new to CI/CD Pipelines in GitLab.

GitHub works just fine have a look: https://github.com/ni920/CICD-Test

Thank you


Here are the CI logs

...
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

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

# 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"]



Advertisement

Answer

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.

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). It is a vast topic on itself but you can get started with GitLab CI‘s documentation: Use Docker to build Docker images


I always use DinD and have a minimal setup in my gitlab-ci.yml.

Using a docker image as a default:

image: docker:19.03.13

Define a default variable for TLS certificates:

variables:
    DOCKER_TLS_CERTDIR: "/certs"

Then use a docker image as a service to enable 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.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement