On this particular error, the problem is that you are "mixing" the commands in a single line, which ends up generating the wrong instructions.
To separate the commands you should use &&
, ;
or ||
- usually these, sometimes |
or |&
is required. In a simplified way:
-
&&
executes the next command only if the previous one executed successfully;
-
||
executes the next command only if it has failed to execute the previous one;
-
;
always executes the next command, regardless of the result of the previous command - when set -e
is not used.
So, where are you using 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 look 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:
- using
MAINTAINER
is obsolete , please use LABEL
- To avoid creating layers by increasing the size of the image, focus the commands in a single statement - 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 did not test the use of the image, I just set it to "build", the apt repository appears to be incorrect as it does not install some dependencies.