E
E
EVOSandru62020-02-28 16:49:02
Docker
EVOSandru6, 2020-02-28 16:49:02

How to COPY a file to a Dockerfile from neighboring folders?

Good afternoon,

There is a structure:

- app
- docker/containers/parser/Dockerfile
- docker-compose.yml

docker-compose.yml

version: '3.7'
services:
parser:
      build: ./docker/containers/parser
      volumes:
          - ./app:/var/www
      working_dir: /var/www
      restart: always
      tty: true


In Dockerfile I try to copy the file:

FROM node:11-slim

WORKDIR /var/www

COPY ../../app/package.json .

...


I catch:

Step 3/9 : COPY ../../app/package.json .
ERROR: Service 'parser' failed to build: COPY failed: Forbidden path outside the build context: ../../app/package.json ()
Makefile:83: recipe for target 'docker-build' failed


As I understand it, I need to somehow use the context of the app

folder Tried like this:

build:
        context: ./app
        dockerfile: ./docker/containers/parser/Dockerfile


What I get:

ERROR: Cannot locate specified Dockerfile:

./docker/containers/parser/Dockerfile To be able to copy the file this way (without moving the Dockerfile )

COPY package.json .
# или COPY ./package.json .


?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Bulatov, 2021-03-02
@EVOSandru6

You need to specify the context for the Dockerfile.
And specify the Dockerfile itself.
An example of how it could be:
docker-compose.yml

version: '2'

services:
    nginx:
        build:
            context:  .
            dockerfile:  ./images/nginx/Dockerfile

./images/nginx/Dockerfile
FROM nginx:latest

COPY ["domains/docker.test", "/var/www/docker-bar.test"]

What does the COPY command in this case need to proceed from the fact that we specify the copy directory not from the place where the Dockerfile is located, but from where the directory is specified in the context parameter in the docker-compose.yml file.

V
Vladimir Kuts, 2020-02-28
@fox_12

build:
context: ./docker/containers/parser/
dockerfile: Dockerfile

and put package.json where you specified the context - in ./docker/containers/parser/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question