错误:Dockerfile解析错误行4:未知指令:PHP7

时间:2019-03-29 13:26:47

标签: php docker docker-compose dockerfile php-7

我有一个dockerfile

enter image description here

FROM alpine:3.7

RUN apk --no-cache add
php7
php7-fpm
php7-pdo
php7-pdo_mysql
php7-mcrypt
php7-mbstring
php7-xml
php7-openssl
php7-json
php7-phar
php7-zip
php7-dom
php7-session
php7-zlib &&
php7 -r "copy('http://getcomposer.org/installer', 'composer-setup.php');" &&
php7 composer-setup.php --install-dir=/usr/bin --filename=composer &&
php7 -r "unlink('composer-setup.php');" &&
ln -sf /usr/bin/php7 /usr/bin/php &&
ln -s /etc/php7/php.ini /etc/php7/conf.d/php.ini

RUN set -x
&& addgroup -g 82 -S www-data
&& adduser -u 82 -D -S -G www-data www-data

COPY . /src
ADD .env.example /src/.env
WORKDIR /src
RUN ["/bin/sh", "-c"," php artisan key:generate"]
RUN chmod -R 777 storage
CMD php artisan serve --host=0.0.0.0

在运行它时,我不断得到

Creating network "portal-modules_default" with the default driver                                                                  
Building fingerprinting                                                                                                            
> ERROR: Dockerfile parse error line 4: unknown instruction: PHP7                                                                    
⚡️  portal-modules 
  

错误:Dockerfile解析错误行4:未知指令:PHP7

关于如何解决该问题的任何提示?

我是否需要将&放在某个地方以容纳命令?

1 个答案:

答案 0 :(得分:3)

问题出在这里

RUN apk --no-cache add
php7
php7-fpm
php7-pdo
php7-pdo_mysql
php7-mcrypt
php7-mbstring
php7-xml
php7-openssl
php7-json
php7-phar
php7-zip
php7-dom
php7-session
php7-zlib &&
php7 -r "copy('http://getcomposer.org/installer', 'composer-setup.php');" &&
php7 composer-setup.php --install-dir=/usr/bin --filename=composer &&
php7 -r "unlink('composer-setup.php');" &&
ln -sf /usr/bin/php7 /usr/bin/php &&
ln -s /etc/php7/php.ini /etc/php7/conf.d/php.ini

如果要多行编写命令,请使用反斜杠(\)符号:

RUN apk --no-cache add \
    php7 \
    php7-fpm \
    php7-pdo \
    php7-pdo_mysql \
    php7-mcrypt \
    php7-mbstring \
    php7-xml \
    php7-openssl \
    php7-json \
    php7-phar \
    php7-zip \
    php7-dom \
    php7-session \
    php7-zlib && \
    php7 -r "copy('http://getcomposer.org/installer', 'composer-setup.php');" && \
    php7 composer-setup.php --install-dir=/usr/bin --filename=composer && \
    php7 -r "unlink('composer-setup.php');" && \
    ln -sf /usr/bin/php7 /usr/bin/php && \
    ln -s /etc/php7/php.ini /etc/php7/conf.d/php.ini

在断行时向每行添加反斜杠。

有用的链接:https://docs.docker.com/develop/develop-images/dockerfile_best-practices/