0
I have the following need: when creating a new container I would like to automatically run the script /usr/local/bin/start
inside the image, this script basically checks whether the variable TIPO_AMBIENTE is equal to Prod, whether to change 2 file parameters.
Obs: initially would like to run this script only when creating the container, however, it is no problem if the only alternative is to run it whenever the container is started.
FROM php:7.2-apache
MAINTAINER Fabio J L Ferreira <[email protected]>
# Instala e configura componentes essenciais
RUN apt-get update && \
a2enmod rewrite && \
apt-get install -y --no-install-recommends unzip git && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer; \
echo "America/Sao_Paulo" > /etc/timezone; \
\
# Configura componentes do Apache e PHP
{ \
echo '<VirtualHost *:80>'; \
echo '\tServerAdmin webmaster@localhost'; \
echo '\tDocumentRoot /var/www'; \
echo; \
echo '\tErrorLog ${APACHE_LOG_DIR}/error.log'; \
echo '\tCustomLog ${APACHE_LOG_DIR}/access.log combined'; \
echo; \
echo '\t<Directory /var/www>'; \
echo '\t\tOptions Indexes FollowSymLinks'; \
echo '\t\tAllowOverride None'; \
echo '\t\tRequire all granted'; \
echo '\t</Directory>'; \
echo '</VirtualHost>'; \
} | tee /etc/apache2/sites-enabled/000-default.conf; \
docker-php-source extract; \
cp /usr/src/php/php.ini-development /usr/local/etc/php/php.ini; \
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/' /usr/local/etc/php/php.ini; \
docker-php-source delete
# Aqui instalamos algumas extensões comumente utilizadas
RUN apt-get install -y --no-install-recommends libjpeg-dev libpng-dev && \
docker-php-ext-configure gd --with-jpeg-dir=/usr/include/ && \
docker-php-ext-install gd; \
\
# Instala a extensão PHP "exif" => http://php.net/manual/en/intro.exif.php
apt-get install -y --no-install-recommends libexif-dev && \
docker-php-ext-install exif; \
\
# Instala as extensões PHP "mysqli pdo_mysql pgsql pdo_pgsql"
apt-get install -y --no-install-recommends libpq-dev && \
docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql && \
docker-php-ext-install mysqli pdo_mysql pgsql pdo_pgsql
# Limpa repositório local
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
WORKDIR /var/www
EXPOSE 80
COPY start /usr/local/bin/
How could I do this? After solving this problem, I need to check if passing this variable in the container creation will have the expected effect.
would not have had to include this in script form in Dockerfile, to be executed in the container creation, ie when "start" the image?
– Fábio Jânio
Ah, yes. If you want it to always run and be embedded in the image, just use CMD at the end of Dockerfile. So whenever the image is used to generate a container, at the end the command will run inside the container. For example, at the end of Dockerfile:
CMD ["/usr/local/bin/start"]
– nbkhope
I even did something like this, however, I was unable to run the container with the -d option
– Fábio Jânio
@Fábiojânio may be because Voce needs to use Tini to run the script. https://github.com/krallin/tini
– nbkhope