docker 复制失败:在GitLab CI/CD管道的构建上下文中未找到文件

5sxhfpxr  于 2022-12-22  发布在  Docker
关注(0)|答案(1)|浏览(218)

所以我试着用一个docker-compose文件从我的GitLab CI/CD管道进行docker-compose构建,但是失败了。在我的PC上通过Windows PowerShell进行同样的尝试就可以了。
GitLab管道出错

Building spotforus-server
Step 1/4 : FROM openjdk:17
 ---> 5e28ba2b4cdb
Step 2/4 : WORKDIR /spotforus
 ---> Using cache
 ---> 795b15010444
Step 3/4 : COPY build/libs/spotforus-0.0.1-SNAPSHOT.jar /spotforus/spotforus.jar
Service 'spotforus-server' failed to build: COPY failed: file not found in build context or excluded by .dockerignore: stat build/libs/spotforus-0.0.1-SNAPSHOT.jar: file does not exist

停靠器合成文件

version: '3.8'

services:
    db:
      image: mysql:latest
      container_name: mysql-db
      ports:
        - "3306:3306"
      restart: always

    spotforus-client:
      build:
        context: ./spotforus-client
        dockerfile: Dockerfile
      container_name: "spotforus-client"
      ports:
        - "80:80"
      depends_on:
        - spotforus-server
    
    spotforus-server:                      
      build: ./spotforus            
      container_name: spotforus-server
      ports:
        - "8080:8080"                       
      restart: always
      depends_on:

停靠文件

FROM openjdk:17
WORKDIR /spotforus
COPY build/libs/spotforus-0.0.1-SNAPSHOT.jar /spotforus/spotforus.jar
ENTRYPOINT ["java","-jar","spotforus.jar"]

Gitlab yml文件

stages:
  - docker

docker:
  image:
    name: docker/compose:latest
  services:
    - docker:dind
  stage: docker
  script:
    - docker-compose build

GitLab运行器配置

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "Runner"
  url = "https://somedomain.gitlab/"
  id = 7341
  token = "BeNAc2f9gFW-sWX6pewA"
  token_obtained_at = 2022-11-08T09:36:30Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "gradle:latest"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock"]
    shm_size = 0

我一直在这里阅读类似的帖子,似乎这个问题是由Docker上下文引起的,所以我试着在我的Docker文件和Docker组成中调整这个问题,但到目前为止没有运气。

s6fujrry

s6fujrry1#

这个问题原来是由.gitignore文件引起的,该文件被设置为排除.jar/build。这就是为什么docker-compose build在本地运行良好,但在Gitlab管道中失败。This comment确实帮助我理解了如何在. gitignore中创建异常。

相关问题