4

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

MukundS
  • 527
  • 1
  • 6
  • 11
  • You can try [these](https://askubuntu.com/questions/365574/installation-of-a-package-with-parameters-being-prompted-on-cli) – Albin Paul Oct 31 '18 at 09:23
  • Actually `Dockerfile` declaration `FROM ubuntu:18.04` will still get from hub.docker.com. Any reason why you want to build it your self? Because docker image with preconfigured apache is already there. Just try `php:7.2-apache`, it will just works effortlessly. – Dharma Saputra Oct 31 '18 at 09:26
  • @DharmaSaputra, yes correct there are various images available for php application, my code is in php5.5 and I have tried many ways but not able to make it work, there is some curl dependency which i am nt able to resolve, if you have some please share. – MukundS Oct 31 '18 at 10:09
  • I hope this config may help you: https://bitbucket.org/dharmasaputra775/docker-php-stack/src/master/, I've use it for php 5.5 in one of my project, and it works as well. Just edit the base image to `php:5.5-fpm`, because the default image is `php:7.2-fpm`. – Dharma Saputra Oct 31 '18 at 10:18

2 Answers2

14

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.

Constantin Galbenu
  • 16,951
  • 3
  • 38
  • 54
0

You can try this (multiple prompts)

apt-get install x y
Meiram Chuzhenbayev
  • 898
  • 1
  • 10
  • 26