基於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的配置:php

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

說明:

mysql

  • 該docker-compose.yml有webmysql兩個容器
  • image 字段: 標識使用的鏡像的名稱,能夠切換,homestead-docker包的做者提供了php5.6/7.0/7.1版本
  • ports 字段: 是端口的映射。第一個 80 是本機的 80 端口;第二個 80 是指容器內部的 80 端口
  • volumes 字段:是指數據卷的映射。nginx

    • f:/works/.composer:/home/homestead/.composer:表示以冒號(:)分割,拆分爲 f:/works/.composer(表示本機的目錄) 跟 /home/homestead/.composer(表示容器內部的目錄地址)。

原文
相關文章
相關標籤/搜索