Search code examples
dockerdocker-composedockerfiledocker-swarmdocker-machine

how can i pass arguments or bypass it in docker build process?


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

eg:

 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

at this step:

 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. Africa 4. Australia 7. Atlantic 10. Pacific 13. Etc
  2. America 5. Arctic 8. Europe 11. SystemV
  3. Antarctica 6. Asia 9. Indian 12. US Geographic area:

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

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

But no result, please help


Solution

  • 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.

    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
    

    You should change Europe and Berlin with wath you want.