title: Docker and Angular CLI app
body: <p>I'm trying to use Docker to containerize an app built using the Angular CLI. It's just the default files that come when you use <code>ng new</code> so that I can learn how to do this. I'm trying to use a two-step build, where the first step runs <code>ng-build --prod --build-optimizer</code>, and then the result of that in the <code>./dist</code> folder is put into a container with Nginx that serves the app. I know that if I manually build the app from my command line, then run a Dockerfile with only the second step that I can get the Angular app to be served, but I'd like Docker to do that for me.</p>
  
  <p>Here's my Dockerfile:</p>
  
  <pre><code>FROM node:8.9-alpine as angular-built
  COPY package.json package.json
  RUN npm install
  COPY . .
  RUN ng build --prod --build-optimizer
  
  FROM nginx:alpine
  LABEL author="Preston Lamb"
  COPY --from=angular-built ./dist /usr/share/nginx/html
  EXPOSE 80 443
  ENTRYPOINT [ "nginx", "-g", "daemon off;" ]
  </code></pre>
  
  <p>I've tried using the <code>node:8.9-alpine</code> base image as well as the <code>johnpapa/angular-cli</code> base image on the first step of the Dockerfile. Everything works until the <code>RUN ng build --prod --build-optimizer</code> command, at which point it fails with this error:</p>
  
  <blockquote>
    <p>Cannot read property 'config' of null
        TypeError: Cannot read property 'config' of null
            at Class.run (/node_modules/@angular/cli/tasks/build.js:15:56)
            at Class.run (/node_modules/@angular/cli/commands/build.js:216:26)
            at resolve (/node_modules/@angular/cli/ember-cli/lib/models/command.js:261:20)
            at new Promise ()
            at Class.validateAndRun (/node_modules/@angular/cli/ember-cli/lib/models/command.js:240:12)
            at Promise.resolve.then.then (/node_modules/@angular/cli/ember-cli/lib/cli/cli.js:140:24)
            at </p>
  </blockquote>
  
  <p>After googling that, I found that it's because the CLI can't find the <code>.angular-cli.json</code> file. Then I read that by default, Linux doesn't copy hidden files, so it doesn't copy the <code>.angular-cli.json</code> file, and that's where the error comes up.</p>
  
  <p>My next step was trying to force that file to be copied. I tried both of the following, putting this step right before the <code>COPY . .</code> command:</p>
  
  <pre><code>COPY .angular-cli.json .angular-cli.json
  </code></pre>
  
  <p>and </p>
  
  <pre><code>RUN shopt -s dotglob
  </code></pre>
  
  <p>The first one doesn't seem to do anything; I got the same error as before. The second one produces a different error:</p>
  
  <pre><code>/bin/sh: shopt: not found
  </code></pre>
  
  <p>So the command I found to run to tell Linux to copy the hidden files as well doesn't work. I saw one question that was different than this but related say to change the shopt call a little to the following:</p>
  
  <pre><code>RUN /bin/sh -c "shopt -s dotglob"
  </code></pre>
  
  <p>But that didn't do anything. I got the same <code>not found</code> error.</p>
  
  <p>So I'm not sure where to go from here. any help would be greatly appreciated.</p>