zoukankan      html  css  js  c++  java
  • 2020系统综合实践(三)

    安装docker-compose

    sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    
    sudo chmod +x /usr/local/bin/docker-compose
    
    sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
    
    docker-compose --version
    

    编写Dockerfile

    (1)、拉取镜像



    (2)、建立文件夹docker_compose 里面有web和mysql_data子文件夹

    (3)、编写文件
    dockerfile_mysql

    dockerfile_php

    dockerfile_nginx

    default.conf

    docker-compose.yml

    index.html

    NGINX SUCCESS
    

    index.php

    <?php phpinfo();?>
    

    使用compose实现多容器运行机制

    sudo docker-compose up -d --build
    



    访问localhost/index.php

    测试

    (1)、数据库连接测试,修改index.php

    <?php
    $servername = "mysql";  
    $username = "root";
    $password = "123456";   
     
    try {
        $conn = new PDO("mysql:host=$servername", $username, $password);
        echo "连接成功"; 
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }
    

    (2)、新建数据库,修改index.php

    <?php
    $servername = "mysql";
    $username = "root";
    $password = "123456";
     
    try {
        $conn = new PDO("mysql:host=$servername", $username, $password);
        echo "连接成功"; 
    
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = "CREATE DATABASE myDB";
    
        // 使用 exec() ,因为没有结果返回
        $conn->exec($sql);
    
        echo "数据库创建成功<br>";
    }
    catch(PDOException $e)
    {
        echo $sql . "<br>" . $e->getMessage();
    }
    $conn = null;
    ?>
    

  • 相关阅读:
    115. Distinct Subsequences
    91. Decode Ways
    72. Edit Distance
    python 输出 a+b
    求次小生成树
    判断最小生成树是否唯一
    二分法求最优值
    黑科技
    线段树+ 区间更新
    2018ICPC青岛赛区J题
  • 原文地址:https://www.cnblogs.com/ycj202595/p/12854284.html
Copyright © 2011-2022 走看看