title: Dockerfile: COPY folder if it exists (conditional COPY)
body: <p>I have Dockerfile for NodeJS application and need to copy <strong>migrations, seeds</strong> folders inside container. But the problem is that all our applications use same Dockerfile, but not all of them work with DB and have <strong>migrations, seeds</strong>.</p>
  <p>Dockerfile:</p>
  <pre><code>...
  # * package json, to be able run `npm run ...`
  COPY ./package.json /app/
  # * migrations, seeds if they exist
  COPY ./migrations/ /app/migrations/
  COPY ./seeds/ /app/seeds/
  ...
  </code></pre>
  <p>Everything work ok, but if we don't have <strong>migrations</strong> folder we will get:</p>
  <pre><code> =&gt; CACHED [app 4/9] COPY --from=builder /app/node_modules /app/node_modules                                                                                                                                                                                              0.0s
   =&gt; CACHED [app 5/9] COPY --from=builder /app/dist /app/dist                                                                                                                                                                                                              0.0s
   =&gt; CACHED [app 6/9] COPY ./package.json /app/                                                                                                                                                                                                                            0.0s
   =&gt; ERROR [app 7/9] COPY ./migrations/ /app/migrations/                                                                                                                                                                                                                   0.0s
  ------
   &gt; [app 7/9] COPY ./migrations/ /app/migrations/:
  ------
  failed to compute cache key: &quot;/migrations&quot; not found: not found
  </code></pre>
  <p>What is the best way to do it?</p>