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

问题描述

我正在尝试将所有文​​件从一个文件夹复制到正在构建的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

解决方法

COPY从Docker客户端的当前目录添加文件。

来自https://docs.docker.com/engine/reference/builder/

COPY obeys the following rules:

The <src> 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.

If <src> is a directory,the entire contents of the directory are copied,including filesystem metadata.

所以请重构docker项目结构并在当前目录结构中复制内容。

,

直接从docker documention

路径必须在构建上下文中;您无法复制../something / something,因为docker构建的第一步是将上下文目录(和子目录)发送到docker守护程序。

或者,您可以像这样更新目录结构:

- 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