Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Multi-stage build - Copy failing

I'm having some issues with a multi-stage Dockerfile for an ejected create-react-app. The Dockerfile is listed below:

FROM node:9.6.1 as builder

RUN mkdir /usr/src/app
WORKDIR /usr/src/app

ENV PATH /usr/src/app/node_modules/.bin:$PATH
COPY package.json /usr/src/app/package.json
RUN npm install --silent
COPY . /usr/src/app

RUN npm run build

FROM nginx:1.13.9-alpine
COPY --from=builder /usr/src/app/build /usr/share/nginx/html
EXPOSE 80

The Dockerfile runs successfully until it gets to step 10 (COPY) where it throws the following error:

COPY failed: stat /var/lib/docker/overlay2/2fc8af4cb8db9777246cae48721d8a93917c73e415a02680f1e3a73c8780b903/merged/usr/src/app/build: no such file or directory

I've googled away but can't find a clear answer. Has anyone experienced anything similar?

like image 743
tombraider Avatar asked Jun 01 '18 20:06

tombraider


1 Answers

When you build the application it's building in another cointainer/layer. You i'll need to build the application before and copy the build folder to /usr/src/app.

So, this is fine:

FROM node:9.6.1 as builder

WORKDIR /usr/src/app

ENV PATH /usr/src/app/node_modules/.bin:$PATH

COPY package.json .
COPY public public
COPY src src

RUN npm install --silent
RUN npm run build

COPY build .

RUN rm -rf src
RUN rm -rf build

FROM nginx:1.13.9-alpine

COPY --from=builder /usr/src/app /usr/share/nginx/html

EXPOSE 80

I'm removing the src and build folders since that's not necessary and can expose an critical part of your application.

Hence, no doubt about the security of dockerizing an application.

like image 122
lukaswilkeer Avatar answered Oct 22 '22 19:10

lukaswilkeer