Skip to content

Instantly share code, notes, and snippets.

@tiagotex
Created January 8, 2016 12:19
Show Gist options
  • Save tiagotex/c0956f97b6b376f744c2 to your computer and use it in GitHub Desktop.
Save tiagotex/c0956f97b6b376f744c2 to your computer and use it in GitHub Desktop.
Use docker to generate config file replacing env variables in template
<?php
class Conf {
public static $SERVER_NAME;
public static $SERVER_DB;
public static function init_values() {
self::$SERVER_NAME = "$NAME";
self::$SERVER_DB = "$DB";
}
}
Conf::init_values();
?>
web:
build: .
ports:
- "8000:80"
environment:
NAME: mysql
DB: gbdbo
FROM php:5.5-apache
COPY . /var/www/html/
RUN docker-php-ext-install mysqli
RUN sed -i '/DocumentRoot/c\DocumentRoot /var/www/html/htdocs' /etc/apache2/apache2.conf
RUN echo 'date.timezone = UTC' >> /usr/local/etc/php/conf.d/php.ini
RUN a2enmod rewrite
RUN apt-get update; apt-get install -y gettext
RUN chmod -R 700 ./generate_config_php
ENTRYPOINT [ "./generate_config_php" ]
CMD ["apache2-foreground"]
#!/bin/sh
export SERVER_NAME=\$SERVER_NAME
export SERVER_DB=\$SERVER_DB
envsubst < Conf.class.php.template > Conf.class.php
exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment