简体   繁体   English

无法从Docker容器运行Apache / php

[英]unable to run Apache/php from docker container

My requirement is using openface i need to train the dataset(images) and test each input image from webinterface (PHP) and all this activity should run from docker container. 我的要求是使用openface,我需要训练数据集(图像)并测试来自webinterface(PHP)的每个输入图像,所有这些活动应从docker容器运行。

I am able to achieve the above requirment on ubuntu machine. 我能够在ubuntu机器上实现以上要求。 we are trying to install the complete setup(apache/php & openface) in docker. 我们正在尝试在Docker中安装完整的安装程序(apache / php&openface)。 currently we are unable to invoke the html files from apache server using docker 目前,我们无法使用docker从apache服务器调用html文件

The following the docker file used to import the project into docker and install apache/PHP. 以下docker文件用于将项目导入docker并安装apache / PHP。 Please let me know if any changes need to be done in the dockerfile. 请让我知道是否需要在dockerfile中进行任何更改。

FROM ubuntu:16.04

RUN apt-get update && \
      apt-get -y install sudo

RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo

ADD opencv-3.0.0 /

ADD openface_setup.sh /

RUN /openface_setup.sh

ADD openface_work /


RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install \
apache2 php7.0 libapache2-mod-php7.0 curl lynx-cur

RUN a2enmod php7.0
RUN a2enmod rewrite

RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.0/apache2/php.ini
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/7.0/apache2/php.ini

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

EXPOSE 8080

VOLUME /var/www/html # **my PHP/html files are located here. In the docker container the html/php files are not reflecting**

ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf

CMD /usr/sbin/apache2ctl -D FOREGROUND

Once the container is started i want the test.html(located in /var/www/html) to be running. 容器启动后,我希望test.html(位于/ var / www / html中)正在运行。

FYI : 仅供参考:

  1. command to created docker image 创建docker镜像的命令

    sudo docker build -t myname/apache-test .

  2. command to start the docker container 命令启动Docker容器

    docker run -p 8080:80 -d <imageid>

I'd suggest to use the official PHP image with a pre-installed Apache installation. 我建议将官方PHP映像与预安装的Apache安装一起使用。

Your project might look like this: 您的项目可能如下所示:

.
├── Dockerfile
└── src
    └── index.php

while your Dockerfile consists of this: 而您的Dockerfile包含以下内容:

FROM php:7.1-apache
# now RUN here your commands to install openface etc.

and your index.php could look like this: 您的index.php可能如下所示:

<?php phpinfo();

Then build the image: 然后构建图像:

docker build -t myapache .
docker run --rm -p 8080:80 -v $(pwd)/src:/var/www/html myapache

http://localhost:8080 shows the php-info page. http:// localhost:8080显示php-info页面。

You can extend the image to your needs and it's much simpler than your approach. 您可以根据需要扩展图像,这比您的方法要简单得多。 Hope this might help. 希望这会有所帮助。

If you do not need to install anything else, you can directly use the php:7.1-apache image when creating a new container. 如果您不需要安装其他任何东西,则可以在创建新容器时直接使用php:7.1-apache映像。

try typing docker ps to get all the processes running in containers. 尝试输入docker ps以使所有进程在容器中运行。 Then just type docker run -it container-id 然后只需键入docker run -it container-id

It will start the apache server and show the address where it hosted it unless you want to add a different one in /etc/docker/daemon.json ( https://docs.docker.com/engine/userguide/networking/default_network/custom-docker0/ ) 这将启动Apache服务器,并显示地址在那里托管,除非你想添加在/etc/docker/daemon.json一个不同( https://docs.docker.com/engine/userguide/networking/default_network/ custom-docker0 /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM