GithubHelp home page GithubHelp logo

ballooninmyhand / dnmp Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 65 KB

Docker 安装 Nginx + PHP7.3 + PHP7.1 + PHP5.6 + MySQL + redis

Dockerfile 64.69% HTML 30.70% PHP 4.61%
dnmp cron nginx redis php yml mysql

dnmp's Introduction

[TOC]

1. 环境要求

  • git
  • docker
  • docker-compose

2. 包含的镜像

  • nginx-1.16.0
  • php7.3.10(包含composer,包含扩展 amqp、bcmath、Core、ctype、curl、date、dom、fileinfo、filter、ftp、gd、hash、iconv、imap、json、libxml、mbstring、memcached、mongodb、mysqlnd、openssl、pcre、PDO、pdo_mysql、pdo_sqlite、Phar、posix、readline、redis、Reflection、session、SimpleXML、SPL、sqlite3、standard、tokenizer、xml、xmlreader、xmlwriter、zip、zlib)
  • php7.1.7
  • php5.6.31
  • redis
  • mysql

3. 操作步骤

  • 克隆项目

git clone https://github.com/ballooninmyhand/dnmp.git

  • 进入目录

cd dnmp

  • 复制并修改配置文件,设置端口号和工作目录

cp env.example .env

  • 复制 docker-compose-example.yml 文件

cp docker-compose-example.yml docker-compose.yml

  • 使用 docker-compose 创建容器,首次运行请加上 --build 参数

docker-compose up -d [--build]

  • 打开浏览器,访问 localhost

  • 停止并销毁容器

docker-compose down

  • 重启某个容器

docker-compose restart 容器1 容器2

4. 安装PHP扩展

  • 如需安装其他 PHP 扩展,请自行修改 Dockerfile 文件

5. 如何设置 cron 定时任务

  • 推荐使用主机的 cron 实现定时任务
  • 每分钟执行 test.php 脚本,dnmp_php 是容器名称,test.php 在工作目录 /var/www/html
*/1 * * * * /usr/bin/docker exec dnmp_php php /var/www/html/test.php

6. 如何在 php 代码中使用 curl

  • 问题:本地开发两个项目 A 和 B,A 需要用到 yar 扩展调用 B 中的一个 rpc 方法,但是发现报错 curl exec failed 'Couldn't connect to server'

  • 原因:项目A中不能解析设置的域名

  • 解决方案:在 docker-compose.yml 中配置静态ip,并在 php 中设置 extra_hosts

    • 配置虚拟网卡driver和subnet:
    networks:
      default:
        driver: bridge
        ipam:
          config:
          - subnet: 10.0.0.0/24
    • 设置nginx的静态ip
    nginx:
        #其他配置...
        networks:
          default:
            ipv4_address: 10.0.0.10
    • 再在php中设置extra_hosts
    php56:
        #其他配置...
        extra_hosts:
          - "project.com:10.0.0.10"
        networks:
          - default
    • 重启服务

7. 为什么 mac 上请求一个接口响应需要很久

  • 问题:在 mac 上开发时,请求一个接口需要1800ms,而在linux上只需要300ms

  • 原因:osxfs 文件系统效率太低,mac 和 container 的文件系统不一样,同步时需要做大量的格式转换。

  • 解决方案:安装 bg-sync,基本原理就是使用 daemon 方式建立一个同步磁盘,然后在 docker 启动容器时挂载这个同步磁盘。具体实现方式可以参考文件 docker-compose-mac.yml

8. 参考链接

dnmp's People

Contributors

ballooninmyhand avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

summer1205

dnmp's Issues

无法拉取到php73镜像

ERROR: pull access denied for registry.cn-hangzhou.aliyuncs.com/balloon/php73, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

$ sudo docker login --username=airmolecheung registry.cn-hangzhou.aliyuncs.com
注册了阿里云,开通容器镜像服务登录后,仍然无法拉取到

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.