<p>Is it possible to copy one stage of a multi-stage Dockerfile into another?</p>

<p>For various business reasons I have been instructed to use a multi-stage Dockerfile, but what I really need to do is combine the appserver image and webserver image. This is fine in docker-compose as you can reference each section - but I am not sure if this can be done over GCP and Kubernetes.</p>

<p>My Dockerfile code is below.</p>

<pre><code>FROM php:7.1-fpm as appserver

RUN apt-get update &amp;&amp; apt-get install -y libpq-dev \
    &amp;&amp; docker-php-ext-install pdo pdo_pgsql pgsql
RUN apt-get update &amp;&amp; \
     apt-get install -y \
         zlib1g-dev \
         &amp;&amp; docker-php-ext-install zip

COPY ./app /var/www/html

FROM nginx:stable-alpine as webserver
COPY ./app /var/www/html/
COPY vhost-prod.conf /etc/nginx/conf.d/default.conf
</code></pre>

<p>Not sure, what are you trying to achieve by your Dockerfile above.</p>

<ul>
<li>multistage build is not for the above purpose</li>
<li>you cannot throw any problem at multi-stage build and solve it</li>
<li>multi-stage build is to build the binaries/code and copy it to the final image so that you dont carry the dev tools into production</li>
</ul>

<p>For your use case , please make two docker files , one for the app, and other for proxy/nginx , build them independently and run/scale them independently.</p>

<p>In case of static content serving from nginx , you just need to run nginx with volume mount of static content.</p>
