Passing environment variables across stages in docker multistage image

I have a docker image which have 4 lower layers. I want to reduce the size of my current image layer using multistage, but this causes a loss of environment , port and cmd config properties. Is there a way to pass on such config variables across stages in dockerfile.

Source: StackOverflow