构建 Docker 映像时出现未知指令:YUM

构建 Docker 映像时出现未知指令:YUM

我的Docker文件:

FROM remote-host

COPY ./conf/nginx.repo /etc/yum.repos.d/nginx.repo

RUN
  yum -y install nginx-1.12.2 openssl --enablerepo=nginx &&
  yum -y install https://centos7.iuscommunity.org/ius-release.rpm &&
  yum -y install https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release -1.0-14.ius.centos7.noarch.rpm &&
  yum -y install
   php71u-fpm
   php71u-cli
   php71u-mysqlnd
   php71u-soap
   php71u-xml
   php71u-zip
   php71u-json
   php71u-mcrypt
   php71u-mbstring
   php71u-zip
   php71u-gd
    --enablerepo=ius && yum clean all

EXPOSE 80 443

VOLUME /war/www/html /var/log/nginx /var/log/php-fpm /var/lib/php-fpm

COPY ./conf/nginx.conf /etc/nginx/conf.d/default.conf

COPY ./bin/start.sh /start.sh

RUN chmod +x /start.sh'

我正在尝试通过运行 docker 文件来创建图像并安装 PHP 包。

但是在运行 Docker-compose 时出现以下错误:

Building remote_host
Sending build context to Docker daemon  5.632kB
Step 1/8 : FROM centos
 ---> 5d0da3dc9764
Step 2/8 : RUN yum -y install openssh-server
 ---> Using cache
 ---> f35cb2e631df
Step 3/8 : RUN useradd remote_user &&     echo "remote_user:1234" | chpasswd &&     mkdir /home/remote_user/.ssh &&     chmod 700 /home/remote_user/.ssh
 ---> Using cache
 ---> cd43cbb20a17
Step 4/8 : COPY remote-key.pub /home/remote_user/.ssh/authorized_keys
 ---> Using cache
 ---> 265df27dac01
Step 5/8 : RUN chown remote_user:remote_user -R /home/remote_user/.ssh/ &&     chmod 700 /home/remote_user/.ssh/authorized_keys
 ---> Using cache
 ---> ede2d6bc1ca1
Step 6/8 : RUN ssh-keygen -A
 ---> Using cache
 ---> d2285793a0a0
Step 7/8 : RUN yum -y install mysql
 ---> Using cache
 ---> 5e32bcb6c255
Step 8/8 : CMD /usr/sbin/sshd -D
 ---> Using cache
 ---> 96a4c1781a8f
Successfully built 96a4c1781a8f
Successfully tagged remote-host:latest
Building web
Sending build context to Docker daemon  8.192kB
Error response from daemon: dockerfile parse error line 6: unknown instruction: YUM
ERROR: Service 'web' failed to build : Build failed

答案1

您的 中有语法错误Dockerfile。您不能在 中将命令放在多行中,Dockerfile除非转义行尾。也就是说,您不能这样写:

RUN
  yum -y install nginx-1.12.2 openssl --enablerepo=nginx &&
  yum -y install https://centos7.iuscommunity.org/ius-release.rpm

但你可以这样写:

RUN yum -y install nginx-1.12.2 openssl --enablerepo=nginx &&  yum -y install https://centos7.iuscommunity.org/ius-release.rpm

或者你可以这样写:

RUN \
  yum -y install nginx-1.12.2 openssl --enablerepo=nginx && \
  yum -y install https://centos7.iuscommunity.org/ius-release.rpm

在这里,我们使用\字符来转义行尾,从而允许我们将命令分布在多个物理行上Dockerfile

因此您的第一个RUN命令可能看起来应该是这样的:

RUN \
  yum -y install nginx-1.12.2 openssl --enablerepo=nginx && \
  yum -y install https://centos7.iuscommunity.org/ius-release.rpm && \
  yum -y install https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release -1.0-14.ius.centos7.noarch.rpm && \
  yum -y install \
   php71u-fpm \
   php71u-cli \
   php71u-mysqlnd \
   php71u-soap \
   php71u-xml \
   php71u-zip \
   php71u-json \
   php71u-mcrypt \
   php71u-mbstring \
   php71u-zip \
   php71u-gd \
    --enablerepo=ius && yum clean all

相关内容