Score:0

How to make a custom docker image can define the ENV variable

de flag

I've created a custom homemade docker image containing the vhosts configuration, how can I define variables like ServerName, DocumentRoot in an ENV when running the container.

Thanks, really appreciate to all answers

Score:1
in flag

You can use the ${APACHE_DOCUMENT_ROOT} notation in the Apache config file.

I took the example from this unanswered question:

<VirtualHost _default_:80>
  ServerSignature Off

  ErrorLog ${APACHE_LOG_DIR}/000-default-error.log
  CustomLog ${APACHE_LOG_DIR}/000-default-access.log combined

  DocumentRoot ${APACHE_DOCUMENT_ROOT}

  <Directory ${APACHE_DOCUMENT_ROOT}>
    Options FollowSymLinks
    AllowOverride all
    Require all granted
  </Directory>
</VirtualHost>

A very basic Dockerfile:

FROM httpd:2.4
COPY *.conf /usr/local/apache2/conf/

Then I started the built container:

mkdir {log,htdocs}
echo "hi" > htdocs/index.html
docker run -d --rm 
  -e APACHE_LOG_DIR=/var/log/apache2 \
  -e APACHE_DOCUMENT_ROOT=/var/www/htdocs/ 
  -v $PWD/htdocs:/var/www/htdocs 
  -v $PWD/log:/var/log/apache2/ 
  -P httpd:test

And it works.

$ curl http://localhost:32768/
hi
$ ls -l log/
total 4
-rw-r--r-- 1 root root 85 Oct  7 15:06 000-default-access.log
-rw-r--r-- 1 root root  0 Oct  7 15:05 000-default-error.log
in flag
Afterthoughts: `DocumentRoot` most probably doesn't need a variable, since it is going to be static. You are rather mounting different volumes in the same place in various containers. The `ServerName` doesn't really need a variable either, it will most probably be handled by a reverse proxy in front of the container.
YonzLeon avatar
de flag
Thank you! actually im just try to know how to make ENV on image regardless of `ServerName` configuration and others
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.