简体   繁体   中英

Use docker image in .gitlab-ci.yml with build essentials and git

Since I want to use docker build and docker-compose in gitlab CI, the image should be specified as image: docker:latest . However, when I run some scripts including git command, it turns out that git and other build-essentials are not included in this image. Even though I use apt-get , the command is still not found.

I think the docker image is based on Alpine and apparently uses a different package manager: apk .

So you can:

  1. Stick to the docker image and use apk instead of apt-get .
  2. Use gitlab/dind:latest image instead as it's based on Ubuntu and contains apt-get .

In both cases it would be better not to run apt-get during the build process because it will slow it down and can possibly fail and make your whole build fail. Instead create your own Docker image based on one of the two images mentioned above and containing the extra tools you need (eg git) and use that own image in .gitlab-ci.yml .

Sample dockerfile for your image

FROM gitlab/dind:latest

RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y git && \
    rm -r /var/lib/apt/lists/*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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