php - 如何在 Docker 中创建 PHP 环境?
问题描述
我正在尝试使用apache2服务器对php web-app进行 dockerize。为 php 和 apache2 创建环境的任何更好的方法。我在互联网云上搜索找不到任何解决方案。
我已经使用 ubuntu:latest 作为基础映像,如果第一个工作比继续进行,我会尝试逐步创建映像。我已经尝试在没有 php 的情况下创建图像并且我成功地运行了 docker 容器但是没有 PHP 没有运行的意义比我采取下一步将 PHP 添加到图像中,现在我被卡住了。
下面有错误的图像。
这是我的 Dockerfile
#Download base image
FROM ubuntu:latest
#Install tzdata and set timezone.
#Update all packages run the 'apt update' command before installing any packages.
#we need to use -y flag otherwise it will ask for yes/no?
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata && apt-get install -y software-properties-common
#Install C/C++
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
#RUN apt install build-essential
RUN apt-get update -y
RUN apt-get install -y gcc
RUN apt-get install -y g++
RUN ln -f -s /usr/bin/gcc /usr/bin/gcc
RUN ln -f -s /usr/bin/g++ /usr/bin/g++
RUN apt-get update -y
RUN add-apt-repository ppa:ondrej/php
# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install \
apache2 php7.4 php7.4-mysql libapache2-mod-php7.4 curl lynx-common
# Enable apache mods.
RUN a2enmod php7.4
RUN a2enmod rewrite
#Remove any unnecessary files
RUN apt-get clean
#Setup Apache2 servers
#Debian configuration requires the environment variables APACHE_RUN_USER, APACHE_RUN_GROUP, and APACHE_PID_FILE to be set
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
#Expose ports
EXPOSE 80
#Change Permission
RUN chmod -R 777 /var/www/html/
#Copy files to webserver
COPY editor /var/www/html/
# Remove Default index.html
RUN rm /var/www/html/index.html
#Start services
CMD ["/usr/sbin/apache2ctl","-D","FOREGROUND"]
谢谢!!
解决方案
g++ 和 gcc 的符号链接不好。
以下对我有用:
#Download base image
FROM ubuntu:latest
#Install tzdata and set timezone.
#Update all packages run the 'apt update' command before installing any packages.
#we need to use -y flag otherwise it will ask for yes/no?
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata && apt-get install -y software-properties-common
#Install C/C++
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
#RUN apt install build-essential
RUN apt-get update -y && apt-get install -y gcc g++
#RUN apt-get install -y gcc
#RUN apt-get install -y g++
#RUN ln -f -s /usr/bin/gcc /usr/bin/gcc
#RUN ln -f -s /usr/bin/g++ /usr/bin/g++
#RUN apt-get update -y
RUN add-apt-repository ppa:ondrej/php
# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install apache2 php7.4 php7.4-mysql libapache2-mod-php7.4 curl lynx-common
# Enable apache mods.
RUN a2enmod php7.4
RUN a2enmod rewrite
#Remove any unnecessary files
RUN apt-get clean
#Setup Apache2 servers
#Debian configuration requires the environment variables APACHE_RUN_USER, APACHE_RUN_GROUP, and APACHE_PID_FILE to be set
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
#Expose ports
EXPOSE 80
#Change Permission
RUN chmod -R 777 /var/www/html/
#Copy files to webserver
COPY editor /var/www/html/
# Remove Default index.html
RUN rm /var/www/html/index.html
#Start services
CMD ["/usr/sbin/apache2ctl","-D","FOREGROUND"]
推荐阅读
- r - 如何在 R 中使用带有决策曲线分析的 plot_roc_components 分别绘制假阳性组?
- c - 我不明白的指针警告
- flutter - 如何在应用程序中添加两个 FAB 一个中心停靠在底部导航中,另一个在正常位置
- c++ - c++ 使用 va_args 从 C 代码调用 fmt 库
- typescript - 打字稿。如何从参数中获取对象中的属性类型作为返回类型
- javascript - Javascript - 用箭头画圆
- swift - Swift 中的函数
- postgresql - 在 Postgres 12 SQL 存储函数中似乎没有触发 COALESCE
- email - Googleappscript 生成的电子邮件正在跳过我的收件箱
- java - 不包含服务器密钥的 FCM