About this specific error, the problem is that you are "mixing" the commands in a single line, which ends up generating wrong instructions.
To separate the commands you must use&&
, ;
or ||
- usually these, sometimes it is necessary |
or |&
. In a simplified form:
&&
executes the next command only if the previous one has successfully executed;
||
executes the next command only if it failed to execute the previous one;
;
always executes the next command, regardless of the result of the previous command - when set -e
not been used.
I mean, where are you wearing this:
RUN apt-get install -y --no-install-recommends apt-utils \
apt-get install -y apache2 \
apt-get install -y wget curl unzip apt-transport-https ca-certificates \
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg \
echo "deb https://packages.sury.org/php/ stretch main" > /etc/apt/sources.list.d/php.list \
apt-get update \
apt-get install -y php7.1 libapache2-mod-php7.1 php7.1-mysql php7.1-curl php7.1-json php7.1-mbstring php7.1-xml php7.1-mcrypt
RUN a2enmod rewrite \
a2enmod php7.1 \
chown -R www-data:www-data /var/www \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer
It should be something like this:
RUN echo "deb https://packages.sury.org/php/ stretch main" > /etc/apt/sources.list.d/php.list; \
apt-get update --fix-missing; \
apt-get upgrade -y; \
apt-get install -y --no-install-recommends apt-utils; \
apt-get install -y apache2 wget curl unzip apt-transport-https ca-certificates; \
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg; \
apt-get install -y php7.1 libapache2-mod-php7.1 php7.1-mysql php7.1-curl php7.1-json php7.1-mbstring php7.1-xml php7.1-mcrypt; \
a2enmod rewrite && a2enmod php7.1; \
mkdir -p /var/www && chown -R www-data:www-data /var/www; \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer; \
rm -rf /var/lib/apt/lists/*
Some other points of observation:
- the use of
MAINTAINER
is obsolete, prefer to use LABEL
- to avoid the creation of layers no need, increasing the image size, concentrate commands in a single instruction - or in scripts - and remove caches that tools like apt leave
A possible final version would be as follows:
FROM debian:stretch
LABEL maintainer "Bruno César <[email protected]>"
RUN echo "deb https://packages.sury.org/php/ stretch main" > /etc/apt/sources.list.d/php.list; \
apt-get update --fix-missing; \
apt-get upgrade -y; \
apt-get install -y --no-install-recommends apt-utils; \
apt-get install -y apache2 wget curl unzip apt-transport-https ca-certificates; \
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg; \
apt-get install -y php7.1 libapache2-mod-php7.1 php7.1-mysql php7.1-curl php7.1-json php7.1-mbstring php7.1-xml php7.1-mcrypt; \
a2enmod rewrite && a2enmod php7.1; \
mkdir -p /var/www && chown -R www-data:www-data /var/www; \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer; \
rm -rf /var/lib/apt/lists/*
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
EXPOSE 80 443
ENTRYPOINT ["/usr/sbin/apache2ctl"]
CMD ["-D", "FOREGROUND"]
I didn’t test the use of the image, I just adjusted it to "buildar", the repository apt seems to be incorrect as it does not install some dependencies.
Did the answer below help you? Is there any other problem? Maybe I can help you
– Bruno César
It helped a lot. Thank you
– Fábio Jânio