Docker muti-stage

10/25/2018

Is it possible to copy one stage of a multi-stage Dockerfile into another?

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.

My Dockerfile code is below.

FROM php:7.1-fpm as appserver

RUN apt-get update && apt-get install -y libpq-dev \
    && docker-php-ext-install pdo pdo_pgsql pgsql
RUN apt-get update && \
     apt-get install -y \
         zlib1g-dev \
         && 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
-- nmcilree
docker-multi-stage-build
dockerfile
kubernetes

1 Answer

10/25/2018

Not sure, what are you trying to achieve by your Dockerfile above.

  • multistage build is not for the above purpose
  • you cannot throw any problem at multi-stage build and solve it
  • 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

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.

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

-- Ijaz Ahmad Khan
Source: StackOverflow