Set values on image build for a Docker container -


let's logged in reynierpm in fedora , build docker image dockerfile. image contain lamp environment. have apache virtual host(vh) default file looks follow:

<virtualhost *:80>     #servername www.example.com      serveradmin webmaster@localhost     documentroot /var/www      <directory /var/www>         allowoverride         require granted     </directory>      errorlog /dev/stdout     customlog /dev/stdout combined </virtualhost> 

as part of built process file copied proper location on image.

can logged in username host , set dynamically vh? @ end following result:

<virtualhost *:80>     servername reynierpm.dev      serveradmin webmaster@localhost     documentroot /var/www      <directory /var/www>         allowoverride         require granted     </directory>      errorlog /dev/stdout     customlog /dev/stdout combined </virtualhost> 

i know can value current user using $(whoami) bash how can insert/set vh file on docker build?

this content of 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 use args

following @elton suggestion added line run file:

sed -i "s/#servername www.example.com/$user_name.dev/g" /etc/apache2/sites-available/000-default.conf 

and try build image as:

docker build --build-arg user_name=$(whoami) -t dev-php55 . 

but failing following message:

one or more build-args [user_name] not consumed, failing build.

what's wrong?

if want value fixed in image, best option use build argument, , text substitution in dockerfile:

from ubuntu                                                                                                                                           arg user_name=unknown                                                                                                                                 run echo built by: $user_name > /builder.txt 

then pass whoami when build:

docker build --build-arg user_name=$(whoami) -t temp . 

the build argument overrides default in dockerfile image has real builder's username:

docker run temp cat /builder.txt                                                                                                                    built by: ubuntu  

edit: build arguments available environment variables during build process. neither variable or value present in final built image. can make use of argument value in build instructions run.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -