Set ENV variable in container is not working, is every under "/usr/local/bin" executed on container run?
You're correct in that items under /usr/local/bin
are not automatically executed.
The Filesystem Hierarchy Standard specifies /usr/local
as a "tertiary hierarchy" with its own bin
, lib
, &c. subdirectories, equivalent in their intent and use to the like-named directories under /
or /usr
but for content installed local to the machine (in practice, this means software installed without the benefit of the local distro's packaging system).
If you want a command to be executed, you need a RUN
that directly or indirectly invokes it.
As for the other matters discussed as this question has morphed, consider the following:
FROM alpineENV foo=barRUN echo $foo >/tmp/foo-valueCMD cat /tmp/foo-value; echo $foo
When invoked with:
docker run -e foo=qux
...this emits as output:
barqux
...because bar
is the environment variable laid down by the RUN
command, whereas qux
is the environment variable as it exists at the CMD
command's execution.
Thus, to ensure that an environment variable is honored in configuration, it must be read and applied during the CMD
's execution, not during a prior RUN
stage.
Multiple problems with your repo:
First of all when using CMD in docker file, the command added after the image name in the docker run : /bin/bash
will override the CMD ["/usr/local/bin/setup_php_settings"]
from your Dockerfile.
Thus your setup_php_settings is never executed!You should use ENTRYPOINT i.s.o. CMD in your Dockerfile. I found good explanation here and here.
In conclusion for the Dockerfile change the CMD [...]
line in:
ENTRYPOINT bash -C '/usr/local/bin/setup_php_settings';'bash'
then you can run your container with:
docker run -it -e HOST_IP=<your_ip_address> -e PHP_ERROR_REPORTING='E_ALL & ~E_STRICT' -p 80:80 --name dev-php5 mmi/dev-php55
No need to add /bin/bash at the end. Check-out test-repo for test-setup.
Secondly, in your /usr/local/bin/setup_php_settings, you should add
a2enmod rewriteservice apache2 restart
at the end, just before
source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND`
this in order for your new settings to be applied in your web app.