dockerwebpackdocker-composedockerfiledocker-cloud

How can I debug dist/ is not generating on Docker Cloud Build?


I’m trying to automate build on dockercloud to build a docker container for my front-end.

enter image description here


I have

web.dockerfile

### STAGE 1: Build ###
FROM node:9.3.0-alpine as builder

COPY package.json ./

RUN npm set progress=false && npm config set depth 0 && npm cache clean --force

## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
RUN npm i
RUN mkdir /web
RUN cp -R ./node_modules ./web

WORKDIR /web

COPY . .

## Build the angular app in production mode and store the artifacts in dist folder
RUN $(npm bin)/ng build --prod --build-optimizer

### STAGE 2: Setup ###

FROM nginx:1.13.8-alpine

COPY nginx.conf /etc/nginx/nginx.conf
COPY site.conf /etc/nginx/conf.d/default.conf
RUN rm -rf /usr/share/nginx/html/*

COPY dist /usr/share/nginx/html/

RUN touch /var/run/nginx.pid && \
  chown -R nginx:nginx /var/run/nginx.pid && \
  chown -R nginx:nginx /var/cache/nginx && \
  chown -R nginx:nginx /usr/share/nginx/html

USER nginx

as you see I already did this line :

RUN $(npm bin)/ng build --prod --build-optimizer

Which it should generate the dist/ folder for me.


I got

This long logs in my docker-cloud

enter image description here

What I don't understand is, it is working fine, when I used that Dockerfile locally.

Should I look into my webpack settings or my Dockerfile syntax ?


Solution

  • Use the --from argument to COPY to set the source location to a previous build stage.

    COPY --from=builder /web/dist /usr/share/nginx/html/
    

    For your local build you probably have a dist/ folder for your local development which is then included in the build context sent to Docker. The local copy is what ends up in the image.