ebbishop ebbishop - 6 days ago 11
Node.js Question

Dockerfile ADD or COPY newly created file to docker image - no such file or directory

I am attempting to run a gulp build process that creates the compiled & minified files that runs an app within the docker build process. I can verify that the gulp process works, but once docker build has finished, the server does not have access to the build files.

docker-compose.yml



build: ${REPO}
depends_on:
- api
ports:
- "8083:8080"
volumes:
- ${REPO}:/usr/src/app


Dockerfile:



FROM python:3.5.1-onbuild
ARG mode=dev
ENV MODE $mode

# Install node.js
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash
RUN apt-get install -y nodejs
RUN node -v
RUN npm -v
RUN cd $(npm root -g)/npm \
&& npm install fs-extra \
&& sed -i -e s/graceful-fs/fs-extra/ -e s/fs\.rename/fs.move/ ./lib/utils/rename.js


# Install deps for & run gulp build
WORKDIR /usr/src/app/app
RUN npm install
RUN npm install --global gulp-cli
RUN npm rebuild node-sass
RUN gulp //creates /dist, sub-directories and build files in /usr/src/app/app
RUN find ./dist //finds all the newly created files expected

WORKDIR /usr/src/app
ADD /usr/src/app/app/dist/ /usr/src/app/app/dist/
RUN ls
EXPOSE 8080
RUN python3 setup.py install
CMD python3 manage.py ${MODE}


To build:
docker-compose build find
.

To run:
docker-compose up -d
.

Running without the ADD line, 4 lines from the end, the build does not fail, but the files in
/dist
are not available to the app. Running with this line, it fails at the
ADD
line:

Step 23 : ADD /usr/src/app/app/dist/ /usr/src/app/app/dist/
ERROR: Service 'find' failed to build: lstat usr/src/app/app/dist/: no such file or directory


I have also tried:

ADD ./app/dist /usr/src/app/app/dist/


which gave the same error message as above. (Though this makes sense to me, since the dist files are not on my machine to begin with.)

Trying:

ADD /usr/src/app/app/dist/* /usr/src/app/app/dist/


gave me:

ERROR: Service 'find' failed to build: No source files were specified


I suspect it's a misunderstanding I have regarding the context & intermediate containers, but I'm out of ideas.

Answer

Take a look at volumes, in https://docs.docker.com/engine/reference/builder/#/volume

The VOLUME instruction creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers.

This will overwrite the new folders created in the build.

You'll have to remove the volumes from docker-compose.yml, and therefore no need for the ADD in the Dockerfile

Comments