You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitLab Shared Runner下npm install后如何构建docker镜像并推送至GitLab Registry

基于GitLab共享Runner构建Docker镜像并推送至GitLab Registry的CI配置方案

问题场景

需求为基于GitLab Shared Runner执行CI流水线,完成Docker镜像构建并推送至GitLab Registry。初始配置中npm install步骤运行无异常,但后续执行docker build操作的job无法正常运行。

初始.gitlab-ci.yml配置

image: node:14.17.3

stages:
  - install
  - build

install_dependencies:
  stage: install
  tags:
    - gitlab-org-docker
  script:
    - pwd
    - npm install

build-job:
  stage: build
  image: docker
  tags:
    - gitlab-org-docker
  script:
    - echo "Compiling the code..."
    - echo "build"
    - docker build -t bmw-frontend-app .
    - docker ps

初始运行截图

解决方案

经排查问题为遗漏了*Docker in Docker(Dind)*服务配置,调整后的可运行配置如下:

image: docker:19.03.13

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
  - node_modules/
  - .next/

stages:
  - build

services:
  - docker:19.03.13-dind

build-job:
  stage: build
  before_script:
    - echo docker login $DOCKER_REGISTRY --username $DOCKER_REGISTRY_USER --password-stdin
  tags:
    - gitlab-org-docker
  script:
    - echo "Compiling the code..."
    - echo "build"
    - docker build -t registry.gitlab.com/areum.lee1/bmwgs_frontend . 
    - docker login registry.gitlab.com -u $DOCKER_REGISTRY_USER -p $DOCKER_REGISTRY_PASS
    - docker push registry.gitlab.com/areum.lee1/bmwgs_frontend

核心调整点

  • 将全局镜像配置改为image: docker:19.03.12
  • 新增了services配置块引入Dind服务

成功运行截图

内容的提问来源于stack exchange,提问作者Matthew

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 11:24:04