Install PHP with a Dockerfile

I would like to install PHP in a Docker container. I know there are ready made containers from PHP but I wanted to do it myself.

Most programs work.

FROM ubuntu:22.04
RUN apt-get -y update && apt-get -y install apache2

But PHP asks questions about geographic area

FROM ubuntu:22.04
RUN apt-get -y update && apt-get -y install php
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   3. Antarctica  5. Arctic  7. Atlantic  9. Indian    11. US
  2. America  4. Australia   6. Asia    8. Europe    10. Pacific  12. Etc

Please select the city or region corresponding to your time zone.

  1. Amsterdam   12. Busingen     23. Kirov       34. Moscow      45. Saratov     56. Vatican
  2. Andorra     13. Chisinau     24. Kyiv        35. Nicosia     46. Simferopol  57. Vienna
  3. Astrakhan   14. Copenhagen   25. Lisbon      36. Oslo        47. Skopje      58. Vilnius
  4. Athens      15. Dublin       26. Ljubljana   37. Paris       48. Sofia       59. Volgograd
  5. Belfast     16. Gibraltar    27. London      38. Podgorica   49. Stockholm   60. Warsaw
  6. Belgrade    17. Guernsey     28. Luxembourg  39. Prague      50. Tallinn     61. Zagreb
  7. Berlin      18. Helsinki     29. Madrid      40. Riga        51. Tirane      62. Zaporozhye
  8. Bratislava  19. Isle_of_Man  30. Malta       41. Rome        52. Tiraspol    63. Zurich
  9. Brussels    20. Istanbul     31. Mariehamn   42. Samara      53. Ulyanovsk
  10. Bucharest  21. Jersey       32. Minsk       43. San_Marino  54. Uzhgorod
  11. Budapest   22. Kaliningrad  33. Monaco      44. Sarajevo    55. Vaduz

Does anyone have any ideas on how to make it work?

My system:

Docker version 24.0.5, build 24.0.5-0ubuntu1~20.04.1
Linuxmint 20.3 una
x86_64 Linux 5.4.0-162-generic
zsh 5.8
Cinnamon 5.2.7

Many thanks!

You can check how the official PHP image is created. The links to the Dockerfiles can be found on GitHub:

It is not just using apt-get. Dependencies can be installed that way but PHP is compiled from sourcecode so you can be sure you are always using the same version. If you are trying to install the command line interface for php cli scripts and mainly for experimenting, apt-get could work, but most of the applications that you can install from APT require systemd which you will not run (easily) in a Docker container.

Regarding the geographic area, my guess is that the following argument is missing from your Dockerfile:

ARG DEBIAN_FRONTEND=noninteractive

Add it after the line of the FROM instruction so APT will know that you don’t have an interactive terminal.

1 Like