Dockerfile not finding one of my includes

203 Views Asked by At

New to Docker and been checking through the docs, but seems as though this is a reasonable first go at a Dockerfile.

I'm running the following Dockerfile, but am encountering a bit of an issue:

FROM iojs:onbuild
COPY ../../webserver/includes/masterconfig.js ../../webserver/includes/masterconfig.js

This is probably a rookie mistake, but your help is appreciated :)

docker build -t nearby-pushes .
Sending build context to Docker daemon 9.728 kB
Sending build context to Docker daemon
Step 0 : FROM iojs:onbuild
# Executing 3 build triggers
Trigger 0, COPY package.json /usr/src/app/
Step 0 : COPY package.json /usr/src/app/
 ---> Using cache
Trigger 1, RUN npm install
Step 0 : RUN npm install
 ---> Using cache
Trigger 2, COPY . /usr/src/app
Step 0 : COPY . /usr/src/app
 ---> 5f4c87e2362c
Removing intermediate container 16a8fb4b4be1
Step 1 : COPY ../../webserver/includes/masterconfig.js ../../webserver/includes/masterconfig.js
INFO[0010] ../../webserver/includes/masterconfig.js: no such file or directory
2

There are 2 best solutions below

1
On BEST ANSWER

The ADD and COPY directives cannot see files which are in parent directories. In other words, you cannot use them with a file path starting with ../.

From the Docker documentation:

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

and

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.

The important words are context of the build. From the docker build documentation:

Builds Docker images from a Dockerfile and a “context”. A build’s context is the files located in the specified PATH or URL. The build process can refer to any of the files in the context. For example, your build can use an ADD instruction to reference a file in the context.

3
On

The error shows that it can not find the masterconfig.js in your directory. Try to use the absolute directory and the dst directory also use the absolute directory like /masterconfig.js e.g.

FROM iojs:onbuild
COPY absolutepath/webserver/includes/masterconfig.js /masterconfig.js

or make sure the dst directory exist,

CMD mkdir -p /webserver/includes
COPY absolutepath/webserver/incldues/masterconfig.js /webserver/incldues/maserconfig.js