简体   繁体   中英

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. Here is my error from my gitlab pipeline when it tries to build the docker image.

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

My gitlab-ci.yml file:

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.

from 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.

Straight from the 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.

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.

Updated Dockerfile:

FROM
RUN

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

WORKDIR
CMD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM