title: How to create Docker multistage build with Linux dependencies and environment vars from parent image?
body: <p>I have an application packages as .bin and it runs on rhel7-init base image. The following is the Dockerfile with the parent image and child image. </p>
  
  <pre><code>FROM registry.access.redhat.com/rhel7-init:7.3 as base
  COPY yum.repos.d/ /etc/yum.repos.d/
  RUN yum -y install sudo systemd
  RUN yum install https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-7-x86_64/pgdg-redhat93-9.4-3.noarch.rpm -y &amp;&amp; \
   yum install -y postgresql94
  RUN export key=value &amp;&amp; \
      installer.bin &amp;&gt; /root/install.log
  
  FROM registry.access.redhat.com/rhel7-init:7.3
  COPY --from=base /opt/app/ /opt/app
  COPY start_app /root/
  RUN chmod +x /root/start_app
  ENTRYPOINT [ "/root/start_app" ]
  </code></pre>
  
  <p>It has a start script given as ENTRYPOINT which configures a few things at runtime as it brings up the container. I copied the installed directory location to the new image from the parent image. </p>
  
  <p>Now when I start my container, it shows dependencies on which sudo packages which were installed in the parent image.</p>
  
  <p>How do I carry forward the installed packages of my parent base image to my new base image without adding too much size?</p>
  
  <p>Can I also carry forward any env variables present in the installer used in the parent base image?</p>