docker - Docker:错误:作业失败:命令以退出代码1终止

标签 docker gitlab dockerfile

我正在尝试将所有文​​件从一个文件夹复制到正在构建的docker镜像内的文件夹中。这是我的gitlab管道尝试构建docker镜像时出现的错误。

Status: Downloaded newer image for nginx:1.18.0-alpine
 ---> 8c1bfa967ebf
Step 2/3 : COPY conf/default.conf /etc/nginx/conf.d/default.conf
COPY failed: Forbidden path outside the build context: ../../src/ ()
 ---> ffbb72db6c26
Step 3/3 : COPY ../../src/ /var/www/html/public
ERROR: Job failed: command terminated with exit code 1
Here is the dockerfile + folder structure
我的gitlab-ci.yml文件:
image: docker:stable

services:
- docker:18-dind
variables:
  DOCKER_HOST: tcp://localhost:2375

php:

  before_script:
    - docker login gitlab.domain.com:5050 -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}
  script:
    - docker build -t gitlab.domain.com:5050/project/php:7.2-fpm ./php-fpm
    - docker push gitlab.domain.com:5050/project/php:7.2-fpm

nginx:

  before_script:
    - docker login gitlab.domain.com:5050 -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}
  script:
    - docker build -t gitlab.domain.com:5050/project/nginx:stable ./nginx
    - docker push gitlab.domain.com:5050/project/nginx:stable

最佳答案

直接从docker documention

The path must be inside the context of the build; you cannot COPY ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.


或者,您可以像这样更新目录结构:
- code
  - nginx
  - php-fpm
  - src
  - Dockerfile
然后更新Dockerfile中COPY命令的源路径。
更新的Dockerfile:
FROM
RUN

COPY php-fpm/php-fpm.d/entrypoint.sh /usr/local/bin/
COPY src/ /var/www/html/public/src/

WORKDIR
CMD

关于docker - Docker:错误:作业失败:命令以退出代码1终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63364503/

相关文章:

docker redis 备份

gitlab - 从Gitlab界面删除按钮

docker - 使用 docker 提供多个 tensorflow 模型

javascript - Gitlab - runner - 退出状态1

reactjs - Dockerfile - npm : not found

Java Testcontainers - 无法连接到暴露的端口

reactjs - 如何在 docker 镜像中运行 Electron 应用程序?

docker - 从 docker 容器内进行端口转发

docker - 将在 docker 容器中运行的 tomcat webapp 连接到 mysql

GitLab CI - 仅在计划的管道上自动运行任务