Hello
I’m coding a very big Dockerfile (more than 1,200 of lines; lot of comments ;)); with a lot of stages and arguments.
In some parts, I’m forced to copy/paste some block of codes and that’s not good at all. So I’m thinking to the concept of templates as we have in YAML
Defaults: &defaults
Company: foo
Item: 123
Computer:
<<: *defaults
Price: 3000
Is there something like that with Dockerfile?
And additional question: how do you manage very big Dockerfile? Did you’ve some tips here? Thanks
In-depth
I’m trying to optimize my Dockerfile to use a lot of stages and improve reusing cache.
My projects are mainly PHP + JS. I’ve a stage for composer, a stage for Yarn and a lot of another stages.
In my composer stage, I’m copying the composer.*
(json and lock) files in the composer image then do a few things like setting the proxy, configure to use force git@ instead of https, … then, finally, run `composer update´.
In my yarn stage, I’m copying the package.*
(json and lock) files in the node image then do a few thinks (uh oh, the same things in fact) then finally run yarn install
In my PHP stages (a lot of stages), I’ve to do a few things like setting once again the proxy, once again for git, one again do things already done in another stages.
So the question: how can I reuse some parts of my Dockerfile in several places ?
Why more than 1,200 lines
Because I use that Dockerfile for all my projects. I’ve build arguments for installing or not PHP Redis, PHP GD, SOAP, XDebug, OPCache, Chrome (for testing automation) and many more.