【问题标题】:Docker LAMP stack - where is the location to keep PHP projects?Docker LAMP 堆栈 - 保存 PHP 项目的位置在哪里?
【发布时间】:2017-05-22 15:34:10
【问题描述】:

我已经在 Docker 之前安装了 LAMP 堆栈。我正在使用这个图像来构建和运行我的 Docker 的 LAMP 堆栈:

$ docker pull linuxconfig/lamp

全部下载安装后:

$ docker run -it linuxconfig/lamp /bin/bash
root@2e80dfd55a6e:/# service apache2 start
[....] Starting web server: apache2AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message

所以在我的http://172.17.0.2/,我可以看到这个默认页面:

但是我在哪里可以找到它的位置以便我可以将我的 PHP 项目放在那里?

这是来自该图像的 DockerFile:

FROM linuxconfig/apache
MAINTAINER Lubos Rendek <web@linuxconfig.org>

ENV DEBIAN_FRONTEND noninteractive

# Main package installation
RUN apt-get update
RUN apt-get -y install supervisor libapache2-mod-php5 php5-mysql mysql-server

# Extra package installation
RUN apt-get -y install php5-gd php-apc php5-mcrypt

# Configure MySQL
RUN sed -i 's/bind-address/#bind-address/' /etc/mysql/my.cnf

# Include supervisor configuration
ADD supervisor-lamp.conf /etc/supervisor/conf.d/
ADD supervisord.conf /etc/supervisor/

# Include PHP Info page
ADD index.php /var/www/html/index.php

# Create new MySQL admin user
RUN service mysql start; mysql -u root -e "CREATE USER 'admin'@'%' IDENTIFIED BY 'pass';";mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;"; 

# Allow ports
EXPOSE 80 3306

# Start supervisor
CMD ["supervisord"]

编辑:

$ sudo docker run --name=lamp -dP -v $PWD/html:/var/www/html linuxconfig/lamp
c2d1687aef21f8a12a7fbb31bf8cf71c1e5adabf381bc6d70e8804c6663f0bc0

还有:

$ sudo docker port lamp
80/tcp -> 0.0.0.0:32769
3306/tcp -> 0.0.0.0:32768

我通过浏览器访问:http://172.17.0.2:32769/

我收到此错误:

【问题讨论】:

    标签: php apache docker dockerfile lamp


    【解决方案1】:

    看看这篇文章是否有帮助:“LAMP ( Linux, Apache, MariaDB, PHP ) stack Docker image deployment

    保存index.php 文件并在新的html 目录中。
    或者,html 目录可能包含您想要的 PHP 应用程序:

    $ mkdir html
    $ vi html/index.php
    $ ls html/
    index.php
    

    在这个阶段,我们准备部署“linuxconfig/lamp” docker 镜像:

    sudo docker run --name=lamp -dP -v $PWD/html:/var/www/html linuxconfig/lamp
    

    这意味着您将主机目录html 挂载到linuxconfig/lamp 容器文件夹/var/www/html 中。 (见“Mount a host directory as a data volume”)

    【讨论】:

    • 感谢您的回答。我现在收到 This site can’t be reached 172.17.0.2 refused to connect. 的错误。请参阅我上面的编辑。谢谢。
    • @teelou 你的操作系统是什么?视窗? Linux?苹果?你用的是什么码头工人?一个基于 VirtualBox 的工具箱?还是 HyperV(适用于 WindowsX 的 Docker)?还是基于 XHyve VM? (适用于 Mac 的 Docker)
    • 我在 Linux Xubuntu 16.04 上。
    • @teelou 您可能不得不忽略 172.17.0.2 ip:这似乎是一条通用消息,也可以在 stackoverflow.com/q/35165370/6309 中看到。本地主机应该足够了。
    • @teelou 在这里看到forums.docker.com/t/…, 172.17.0.2 必须是您容器的 IP(这是 Apache 从所述容器启动时报告的),但从您的主机,您应该只使用 localhost .
    猜你喜欢
    • 2015-12-22
    • 2013-01-07
    • 2015-12-05
    • 1970-01-01
    • 2022-01-08
    • 2016-02-12
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多