简体   繁体   English

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

[英]Docker: ERROR: Job failed: command terminated with exit code 1

I am trying to copy all the files from a folder into a folder within a docker image as it's being built.我正在尝试将文件夹中的所有文件复制到正在构建的 docker 映像中的文件夹中。 Here is my error from my gitlab pipeline when it tries to build the docker image.这是我的 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这里是 dockerfile + 文件夹结构

My gitlab-ci.yml file:我的 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 adds files from your Docker client's current directory. COPY从您的 Docker 客户端的当前目录添加文件。

from https://docs.docker.com/engine/reference/builder/来自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.

so please restructure the docker project structure and COPY the content inside the current directory structure.所以请重新构建 docker 项目结构并复制当前目录结构内的内容。

Straight from the docker documention直接来自docker 文档

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.您不能 COPY../something /something,因为 docker 构建的第一步是将上下文目录(和子目录)发送到 docker 守护程序。

As an alternative, you can update the directory structure like this:作为替代方案,您可以像这样更新目录结构:

- code
  - nginx
  - php-fpm
  - src
  - Dockerfile

Then update the source path for COPY command in Dockerfile.然后更新 Dockerfile 中COPY命令的源路径。

Updated Dockerfile:更新了 Dockerfile:

FROM
RUN

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

WORKDIR
CMD

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:作业失败:命令以退出代码1终止 - ERROR: Job failed: command terminated with exit code 1 命令以非零退出代码终止:在Docker Container中执行错误:137(Mongo Manager) - command terminated with non-zero exit code: Error executing in Docker Container: 137 (Mongo Manager) Openshift命令以非零退出代码终止:在Docker容器中执行错误:137 - Openshift command terminated with non-zero exit code: Error executing in Docker Container: 137 Gitlab CI 失败并出现错误:作业失败:退出代码 1 - Gitlab CI fails with ERROR: Job failed: exit code 1 在 pod 触发 kubectl exec 命令后,如何查找以退出代码 137 错误终止的命令的日志 - How to find logs for command terminated with exit code 137 error after kubectl exec command is triggered at pod Pod 因错误和退出代码原因终止:1 - Pod terminated with reason Error and Exit Code: 1 Solve 命令在 pod Kubernetes 中以退出代码 137 终止 - Solve command terminated with exit code 137 in pod Kubernetes 使用 visual studio 时如何修复“Docker 命令失败,退出代码为 125” - How to fix 'Docker command failed with exit code 125' when using visual studio Docker 纱线构建失败,退出代码为 1 - Docker yarn build failed with exit code 1 Docker远程API执行程序:命令退出代码 - Docker Remote API exec: Command exit code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM