Closed pavel-mironchik closed 4 years ago
@pavel-mironchik thanks for reporting all the issues that you have, I really appreciate it!
I am not sure at the time I originally wrote the manuscript for this chapter if build args were available (I started writing it back in 2016), however, it looks like an oversight on my part either way considering it is possible as you mention. I will figure out a better way to demonstrate this, because I think you're right that there are far better solutions, even if the reader is very new to docker build
.
Here's a little more info into my thought process:
I prefer to control things like this at runtime (in the CMD) with environment configuration, however, perhaps I could briefly introduce build args at that point in chapter 4 to give readers better options at that point in the book. 🤔
The goal of chapter 4 is to not delve into CMD yet, so I proposed another solution based on the knowledge of someone new to Docker. I admitted in the text that the approach was a "hack", but wanted to start demonstrating how to use environment to control runtime behavior. I give ample warning that it's not the ideal way to do it, with promise of following up later in the text.
While build args are useful, I prefer a consistent build each time for my applications and to control these types of things at runtime. Later in the book, I cover the CMD instruction and using environment variables to control things like caching, running "warmup" commands, etc, and disabling XDebug.
Laradoc's goal is different in some ways from a typical application Dockerfile
. Laradoc also supports multiple PHP versions, so build args are a really powerful way for them to create variant builds from the same Dockerfile, but I am of the opinion that conditional RUN
instructions introduce a layer of complexity in a Dockerfile that I avoid in projects that don't need them. I prefer to have a single, consistent, build that can be altered at runtime via environment. It's a preference, so I will consider how to best introduce build args, I think that's a good idea.
@paulredmond yeah, I fully understand your point of view. My intent was to point out to another possibility, and I really was sad when I read the book until the end and didn't see such (I mean ARG
and RUN if
). Of course, it is a matter of taste and I guess I'm used to Laradock and it's way to do things. Anyway, I think if you consider to include an example with these operators, the book will become even more useful.
It's great feedback @pavel-mironchik, thank you! While I don't use build args often, I feel like it's a concept worth covering with readers. 👍
Removed erroneous statement in preview version of the book. Still needs verification after PDF renders. No ETA yet on publish date.
Verified in rendered PDF preview for Leanpub and Fancy custom render PDF.
You write in "fancy" version:
Why can't we control that? Take a look at how Laradock project uses an environment variable to conditionally install XDebug: https://github.com/laradock/laradock/blob/master/php-fpm/Dockerfile#L108
For me, their approach looks simpler and more elegant. And I also noted that you're familiar with environment variables and uses them through the book and even in the chapter about XDebug.