国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 服務器 > Web服務器 > 正文

利用docker搭建LAMP運行環境教程詳解

2024-09-01 13:48:30
字體:
來源:轉載
供稿:網友

LAMP介紹

LAMP 指的 Linux(操作系統)、ApacheHTTP 服務器,MySQL(有時也指MariaDB,數據庫軟件) 和 PHP(有時也是指 Perl 或 Python) 的第一個字母,一般用來建立 web 服務器。 雖然這些開放源代碼程序本身并不是專門設計成同另幾個程序一起工作的,但由于它們的免費和開源,這個組合開始流行(大多數Linux發行版本***了這些軟件)。當一起使用的時候,它們表現的像一個具有活力的解決方案包。

下面介紹如何使用docker來搭建一個包含lamp組件的容器:

從網站上 pull 一個 lamp 鏡像

官方的倉里沒有標 OFFICIAL 的 lamp 的鏡像,不過 「tutum」的鏡像做的非常好,我們可以直接 pull 他們的鏡像來完成我們的操作。

"lang-bash">core@localhost ~/base $ docker pull tutum/lampPulling repository tutum/lampb32789c7d66: Download complete...

使用默認方式啟動 lamp 容器

"lang-bash">core@localhost ~/base $ docker run "hljs-operator">-d -p : -p : tutum/lamp ee00c97a5cdefb985baf826c16723f333aa5edddee4072a5107c724ad09f10dcore@localhost ~/base $ docker psCONTAINER ID    IMAGE               COMMAND        CREATED       STATUS       PORTS                     NAMESee00c97a5 "hljs-built_in">cd    tutum/lamp:latest         "/run.sh"        seconds ago    Up seconds    0.0.0.0:->/tcp, 0.0.0.0:->/tcp  lonely_davincie3c136d76b44    tutum/tomcat: "hljs-number">8.0          "hljs-string">"/run.sh"        minutes ago   Up minutes    "hljs-number">0.0. "hljs-number">0.0:->/tcp              tomcat001fe9e65aaf58c    dl.dockerpool.com:/mysql: "hljs-number">5.7  "hljs-string">"/entrypoint.sh mysq  51 minutes ago   Up 51 minutes    3306/tcp                    db001,tomcat001/tomysqlcore@localhost ~/base $ curl http://127.0.0.1:8080

#使用curl可以查看到默認的應用已經啟動

<html><head>    <title>Hello world!</title>    <style>    body {        background-color: white;        text-align: center;        padding: 50px;        font-family: "Open Sans "hljs-string">","Helvetica Neue "hljs-string">",Helvetica,Arial,sans-serif;    }    #logo {        margin-bottom: 40px;    }    </style></head><body>    <img id="logo "hljs-string">" src="http://upload.server110.com/image/20141116/205R55010-0.png" />    <h1>Hello world!</h1>            <h2>MySQL Server version: 5.5.38-0ubuntu0.14.04.1</h2>    </body></html>

部署自己的 PHP 應用

默認的容器啟動了一個 helloword 應用,我們可以使用 dockerfile 創建另外一個鏡像來部署我們自己的應用程序,dockerfile 的詳細語法將在后面章節介紹。

core@localhost ~ $ mkdir phpcore@localhost ~ $ cd php/core@localhost ~/php $ touch Dockerfilecore@localhost ~/php $ vi Dockerfilecore@localhost ~/php $ docker build -t dockerpool/my-lamp-app .

Dockerfile 內容如下:

FROM tutum/lamp:latestRUN rm -fr /app && git clone https://github.com/username/customapp.git /app#這里替換 https://github.com/username/customapp.git 地址為你自己的項目地址EXPOSE 80 3306CMD ["/run.sh"]

再次啟動自己的容器就完成部署了

"lang-bash">core@localhost ~/php $ docker stop  eeeecore@localhost ~/php $ docker rm eeeecore@localhost ~/php $ docker run "hljs-operator">-d -p : -p : dockerpool/my-lamp-app

使用 curl看下自己的應用程序是不是已經正確啟動了吧!

curl http://localhost/

在 php 程序中連接數據庫 在容器中訪問 mysql 數據庫

這個鏡像的 mysql 數據庫有個默認的 root 用戶,本地連接時可以不用密碼,所以在代碼訪問非常簡單。

"hljs-preprocessor"><?php$mysql = "hljs-keyword">new mysqli( "hljs-string">"localhost", "hljs-string">"root");echo "hljs-string">"MySQL Server info: ". "hljs-variable">$mysql "hljs-variable">->host_info;?>

在容器外部訪問 mysql 數據庫

當我們第一次以 tutum/lamp 鏡像啟動容器的時候,它會自動創建一個叫 admin 的 mysql 用戶,并生成一個隨機密碼,使用「docker logs +容器ID」可以獲取到這個密碼。

"lang-bash">core@localhost ~/php $ docker logs cb=> An empty or uninitialized MySQL volume is detected in /var/lib/mysql=> Installing MySQL ...=> Done!=> Waiting "hljs-keyword">for confirmation of MySQL service startup=> Creating MySQL admin user with random password=> Done!========================================================================You can now connect to this MySQL Server using:  mysql -uadmin -p2Ijg6gvmM0N3 -h<host> -P<port>Please remember to change the above password as soon as possible!MySQL user "hljs-string">'root' has no password but only allows local connections========================================================================

默認的 root 用戶無法遠程登陸,所以要使用 admin 用戶,它同樣具有 root 權限。

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家用docker搭建LAMP能有所幫助,如果有疑問大家可以留言交流。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 清新县| 通江县| 沁水县| 广河县| 晋州市| 建始县| 忻州市| 巫溪县| 榆社县| 苏州市| 清苑县| 澄迈县| 南皮县| 永州市| 上栗县| 常德市| 浮梁县| 长乐市| 万全县| 西吉县| 汶川县| 酉阳| 虞城县| 竹溪县| 开阳县| 峨山| 托克托县| 会理县| 莱西市| 万州区| 太保市| 兴安盟| 浦东新区| 抚远县| 奇台县| 十堰市| 洱源县| 图木舒克市| 永福县| 丰都县| 从化市|