Code Monkey home page Code Monkey logo

php-docker-dev's Introduction

[TOC]

开发环境Docker化 之 世界上最好的语言

安装Docker环境

http://docker.io/ 下载Mac桌面版

怎么下载大家都知道的,不解释

获取docker开发环境脚本

  • git clone https://github.com/hundredlee/php-docker-dev.git

  • 目录结构如下

├── app
│   └── demo
│       └── public
│           └── index.php
├── docker-compose.yml
├── readme.md
└── services
    ├── console
    │   ├── Dockerfile
    │   └── composer.phar
    ├── php
    │   ├── Dockerfile
    │   └── config
    │       ├── opcache.ini
    │       └── php.ini
    ├── redis
    │   ├── Dockerfile
    │   └── redis.conf
    └── web
        └── config
            ├── demo.conf

运行demo项目

打开iTerms 进入根目录,并顺序运行以下两条命令

docker-compose build

docker-compose up -d

将127.0.0.1 demo.dev 加入hosts文件中

打开浏览器访问 http://demo.dev

如果你看到了phpinfo();的界面,那么你已经成功了。

添加本地开发项目

  • 1.打开docker-compose.yml
  • 2.找到services -> php -> volumes
  • 3.添加映射本地开发项目的绝对路径至容器的目录(目前我是直接映射到容器的/mnt目录,没毛病)
  • 4.例如 - /Users/hundredlee/PHPStorm/project:/mnt/project

新建并添加nginx配置文件

  • 配置文件模板,添加项目的nginx conf文件至services -> web -> conf
server {
  listen       80;
  server_name  demo.dev;
  root          /mnt/demo/public;
  index         index.php;

  location / {
     try_files $uri $uri/ /index.php?$query_string;
   }

  location ~ \.php$ {
     fastcgi_pass   php:9000;
     fastcgi_index  index.php;
     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     include        fastcgi_params;
  }
}

注意事项

MySQL

  • 在本地连接数据库的时候
    • Hostname : 127.0.0.1
    • username : dev
    • password : 123456

Redis

  • 项目中的REDIS_HOST=redis

php-docker-dev's People

Contributors

hundredlee avatar jrocoin2016 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.