Gitlab CI / Docker: Use custom image for job

2020-08-10 08:08发布

问题:

This is how I do some linter test (eslint).

linter:
  image: ubuntu:16.04
  stage: test
  tags:
    - testing
  before_script:
    - apt-get update -y
    - apt-get install nodejs-legacy -yqq
    - apt-get install curl -yqq
    - curl https://install.meteor.com/ | sh
    - meteor npm install eslint eslint-plugin-react
  script:
    - ./node_modules/.bin/eslint --ext .js --ext .jsx .

But with this every test will have to install the packages to the ubuntu image, which takes time.

So I thought to build a image with exact this. I came up with this Dockerfile:

FROM ubuntu:16.04
RUN apt-get update -y
RUN apt-get install nodejs-legacy -yqq
RUN apt-get install curl -yqq
RUN apt-get clean && apt-get autoclean && apt-get autoremove
RUN curl https://install.meteor.com/ | sh

Then I do

$ docker build -t linter-testing:latest .

and this yml file:

linter:
  image: linter-testing:latest
  stage: test
  tags:
    - testing
  before_script:
    - meteor npm install eslint eslint-plugin-react
  script:
    - ./node_modules/.bin/eslint --ext .js --ext .jsx .

But it fails with this error:

ERROR: Job failed: Error response from daemon: repository linter-testing not found: does not exist or no pull access

So why is this image not existing, althoug docker images shows me exact that image...

回答1:

You need to edit your config.toml file which is in /etc/gitlab-runner on your runner machine with the following

[runners.docker]
  pull_policy = "if-not-present"

See related issue here.