我如何在 docker build 过程中传递参数或绕过它? [英] how can i pass arguments or bypass it in docker build process?

查看:36
本文介绍了我如何在 docker build 过程中传递参数或绕过它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的 PHP 应用程序编写了一个 Dockerfile,而不是从 dockerhub 我从头开始创建它.

I writing a Dockerfile for my PHP application, and instead of from dockerhub i am creating it from scratch.

例如:

 FROM ubuntu:18.04
 RUN apt-get update && 
       apt-get install -y --no-install-recommends apt-utils && 
       apt-get -y install sudo

 RUN sudo apt-get install apache2 -y
 RUN sudo apt-get install mysql-server -y
 RUN sudo apt-get install php libapache2-mod-php -y 
 RUN rm -rf /var/www/html/
 COPY . /var/www/html/
 WORKDIR /var/www/html/
 EXPOSE 80
 RUN chmod -R 777 /var/www/html/app/tmp/

 CMD systemctl restart apache2

在这一步:

 RUN sudo apt-get install php libapache2-mod-php -y

我卡住了,因为它要求用户输入,例如::

I get stuck, because it asks for user input, like::

请选择您居住的地理区域.后续配置问题将通过提供城市列表来缩小范围,代表它们所在的时区.

Please select the geographic area in which you live. Subsequent configuration questions will narrow this down by presenting a list of cities, representing the time zones in which they are located.

  1. 非洲 4. 澳大利亚 7. 大西洋 10. 太平洋 13. 等等
  2. 美国 5. 北极 8. 欧洲 11. SystemV
  3. 南极洲 6. 亚洲 9. 印度 12. 美国地理区域:

我无法继续前进,我尝试过这样:

I am not able to move ahead of this, i tried like this:

RUN sudo apt-get install php libapache2-mod-php -y 9

但没有结果,请帮忙

推荐答案

您可以在 Dockerfile 中设置环境变量 DEBIAN_FRONTEND=noninteractiveDEBCONF_NONINTERACTIVE_SEEN=true,在代码>运行 sudo apt-get install php libapache2-mod-php -y.

You could set the environment variables DEBIAN_FRONTEND=noninteractive and DEBCONF_NONINTERACTIVE_SEEN=true in your Dockerfile, before RUN sudo apt-get install php libapache2-mod-php -y.

您的 Dockerfile 应如下所示:

Your Dockerfile should look like this:

FROM ubuntu:18.04


RUN apt-get update && 
       apt-get install -y --no-install-recommends apt-utils && 
       apt-get -y install sudo

RUN sudo apt-get install apache2 -y
RUN sudo apt-get install mysql-server -y


## for apt to be noninteractive
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true

## preesed tzdata, update package index, upgrade packages and install needed software
RUN echo "tzdata tzdata/Areas select Europe" > /tmp/preseed.txt; 
    echo "tzdata tzdata/Zones/Europe select Berlin" >> /tmp/preseed.txt; 
    debconf-set-selections /tmp/preseed.txt && 
    apt-get update && 
    apt-get install -y tzdata



RUN sudo apt-get install php libapache2-mod-php -y
RUN rm -rf /var/www/html/
COPY . /var/www/html/
WORKDIR /var/www/html/
EXPOSE 80
RUN chmod -R 777 /var/www/html/app/tmp/

CMD systemctl restart apache2

您应该根据需要更改 EuropeBerlin.

You should change Europe and Berlin with wath you want.

这篇关于我如何在 docker build 过程中传递参数或绕过它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆