基于homestead-docker的PHP开发环境

1. 安装docker环境,for win
2. clone homestead for docker的package:git clone https://github.com/shincoder/homestead-docker.git
3. pull homestead image: docker pull shincoder/homestead:php7.1
4. copy && edit docker-compose.yml
$ cp docker-compose.dist.yml docker-compose.yml
$ vim docker-compose and like follow
5. 连接web容器:
# 密码是secret
ssh homestead@localhost`
6. 连接数据库:
# 密码为docker-compose.yml上的 【MYSQL_ROOT_PASSWORD: 'root'】即:root
# or 有可能是密码为空,即直接: `mysql -uroot -p` 直接回车
mysql -uroot -p

如下是我homestead-docker.yml的配置:

web:
    image: shincoder/homestead:php7.0
    restart: unless-stopped
    ports:
        - "80:80" # web
        - "22:22" # ssh
    volumes:
        - f:/works/.composer:/home/homestead/.composer # composer caching
        - f:/works/.gitconfig:/home/homestead/.gitconfig # Git configuration ( access alias && config )
        - f:/works/.ssh:/home/homestead/.ssh # Ssh keys for easy deployment inside the container
        - f:/works/web:/apps # all apps
        - f:/works/nginx/sites-available:/etc/nginx/sites-available # nginx sites ( in case you recreate the container )
        - f:/works/nginx/sites-enabled:/etc/nginx/sites-enabled # nginx sites ( in case you recreate the container )
        - f:/works/nginx/ssl:/etc/nginx/ssl
    links:
        - mysql

mysql:
    image: mysql:5.7
    restart: unless-stopped
    ports:
        - "3306:3306"
    environment:
        MYSQL_ROOT_PASSWORD: 'root'
    volumes:
        - f:/docker/mysql:/var/lib/mysql

说明:

  • 该docker-compose.yml有webmysql两个容器
  • image 字段: 标识使用的镜像的名称,可以切换,homestead-docker包的作者提供了php5.6/7.0/7.1版本
  • ports 字段: 是端口的映射。第一个 80 是本机的 80 端口;第二个 80 是指容器内部的 80 端口
  • volumes 字段:是指数据卷的映射。

    • f:/works/.composer:/home/homestead/.composer:表示以冒号(:)分割,拆分为 f:/works/.composer(表示本机的目录) 跟 /home/homestead/.composer(表示容器内部的目录地址)。

原文

相关推荐