"COPY failed: no source files were specified" when Dockerfile is not in root directory on Docker Hub

Viewed 1152

When I run my application through docker-compose up, it builds and runs without any issues. When I try to host it on Docker Hub, it fails to build with the error COPY failed: no source files were specified. I believe it is because the Dockerfile is not in the root directory.

My folder structure is like this:

root
-- docker-compose.yml
-- app
   -- Dockerfile
   -- package.json
   -- package-lock.json
   -- src
      -- .....

My Dockerfile is below, and when I run docker-compose up (which points to the Dockerfile within /app) it runs fine:

FROM node:8.10.0-alpine
WORKDIR /usr/src/app
COPY package*.json /usr/src/app/
RUN npm install --production
COPY . /usr/src/app
EXPOSE 4000
CMD ["npm", "run", "app"]

I am wanting to host my project on Docker Hub, but I'm getting the following error:

Step 1/7 : FROM node:8.10.0-alpine
---> adc4b0f5bc53
Step 2/7 : WORKDIR /usr/src/app
Removing intermediate container 743246352cea
---> 3dcb720d4618
Step 3/7 : COPY package*.json /usr/src/app/
COPY failed: no source files were specified

The build rules I've set to point to the correct Dockerfile location is below:

Docker Hub build rules showing Dockerfile location as app/Dockerfile

Is my Dockerfile wrong, or am I not configuring Docker Hub correctly when I try to hook it up to my GitHub repo?

For context, the GitHub repo is here.

1 Answers

In the build configuration, you need to configure the "build context" directory rather than changing the Dockerfile location. Otherwise, the build will run in the parent of your github repo where the package*.json files do not exist. Note the column after "Dockerfile location" when configuring automated builds in the example below:

enter image description here

Related