I'm wondering if some of the variables declared with ENV that are just used to build the image should be instead declared with ARG. For example:
ENV PHP_EXTRA_CONFIGURE_ARGS --with-apxs2 --disable-cgi
https://github.com/docker-library/php/blob/master/7.1/stretch/apache/Dockerfile#L101
That variable seems just used to compile php when the image is built. Declaring it with ARG will give other the ability to override it using --build-args to pass different flags when the image is built instead of having to fork(for example in a ci/cd pipeline). ENV only allows overriding when the container runs even though at that point the variable is not useful because php has been already compiled.
It worth notice that variables defined with ENV are passed as environment variables when the container runs even though they are not useful anymore. ARG would fix that behaviour.
# env | grep -i php
PHP_EXTRA_CONFIGURE_ARGS=--with-apxs2 --disable-cgi
PHP_ASC_URL=https://secure.php.net/get/php-7.1.19.tar.xz.asc/from/this/mirror
PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2
PHP_EXTRA_BUILD_DEPS=apache2-dev
PHP_LDFLAGS=-Wl,-O1 -Wl,--hash-style=both -pie
PHP_INI_DIR=/usr/local/etc/php
PHP_URL=https://secure.php.net/get/php-7.1.19.tar.xz/from/this/mirror
PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2
PHP_VERSION=7.1.19
PHP_MD5=
PHP_SHA256=7cab88f269b90a8a38dbcccf3ec0d5c6eba86122431a53eaa94405bbb60370a8
This variable is used in our templating (and is not intended to be user-serviceable); see:
vs:
vs:
I am personally not a fan of ARG unless necessary, especially given that it makes the output of docker history unnecessarily difficult to parse (both for humans and for computers).
+1 for using using ARG. There's currently no way to customize PHP build without forking. While I understand this repo, first and foremost, is to let you maintain the images, it would be extremely great of you to use ARG to let the community use these Dockerfiles without forking. It would make maintenance of custom PHP builds based on "official" images extremely easy. (Hopefully without making YOUR maintenance of these images any less inconvenient)
ARG is not great unless necessary, especially given that it makes the output of docker history unnecessarily difficult to parse for both for humans and for computers.
I don't see a problem with having to fork the repo to change the build. A CI server that does a git clone --depth 1 with a sed is not that complex.
@Nowaker is right. It MUST BE ARG instead of ENV.
Can you change www-data for any other user by using PHP_EXTRA_CONFIGURE_ARGS environment variable on PHP-FPM?
We cannot make ENV a global for multistage build purpose. However, the ARG is able to. The documentation says so.
Am I obligated to use --build-arg at build time?
C/C @yosifkit
Most helpful comment
+1 for using using ARG. There's currently no way to customize PHP build without forking. While I understand this repo, first and foremost, is to let you maintain the images, it would be extremely great of you to use ARG to let the community use these Dockerfiles without forking. It would make maintenance of custom PHP builds based on "official" images extremely easy. (Hopefully without making YOUR maintenance of these images any less inconvenient)