Let's say that I am logged in as reynierpm
in my Fedora and I will build a Docker image from a Dockerfile. That image will contain a LAMP environment. I have a Apache Virtual Host(VH) default file that looks as follow:
<VirtualHost *:80>
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory /var/www>
AllowOverride All
Require all granted
</Directory>
ErrorLog /dev/stdout
CustomLog /dev/stdout combined
</VirtualHost>
As part of the built process this file is copied to the proper location on the image.
Can I get the logged in username from the host and set dynamically into this VH? At the end I would like to get the following result:
<VirtualHost *:80>
ServerName reynierpm.dev
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory /var/www>
AllowOverride All
Require all granted
</Directory>
ErrorLog /dev/stdout
CustomLog /dev/stdout combined
</VirtualHost>
I know that I can get the value for the current user using $(whoami)
from bash but how I can insert/set it to the VH file on Docker build?
This is the content of the Dockerfile
:
FROM ubuntu:14.04.5
MAINTAINER Me <myemail@gmail.com>
ARG USER_NAME=unknown
VOLUME ["/var/www"]
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive \
apt-get install -y software-properties-common && \
apt-get update && \
apt-get install -y \
apache2 \
php5 \
php5-cli \
libapache2-mod-php5 \
php5-gd \
php5-json \
php5-mcrypt \
php5-mysql \
php5-xdebug \
php5-curl \
php5-memcached \
php5-mongo \
zend-framework \
mc \
nano
# Copy default virtual host file.
COPY /config/apache2_vhost/apache_default /etc/apache2/sites-available/000-default.conf
COPY run /usr/local/bin/run
RUN chmod +x /usr/local/bin/run
RUN a2enmod rewrite
EXPOSE 80
EXPOSE 9001
CMD ["/usr/local/bin/run"]
UPDATE: build fails while try to use the args
Following @Elton suggestion I added this line to the run
file:
sed -i "s/#ServerName www.example.com/$USER_NAME.dev/g" /etc/apache2/sites-available/000-default.conf
And then try to build the image as:
docker build --build-arg USER_NAME=$(whoami) -t dev-php55 .
But is failing with the following message:
One or more build-args [USER_NAME] were not consumed, failing build.
What's wrong?