Table of Contents
什么是LaraDock
Docker vs Vagrant
LaraDock内置软件
系统要求
使用教程
GitHub地址
Home Backend Development PHP Tutorial LaraDock -- Docker 版 Laravel Homestead:让你在Docker中轻松运行Laravel应用

LaraDock -- Docker 版 Laravel Homestead:让你在Docker中轻松运行Laravel应用

Jun 23, 2016 pm 01:13 PM

什么是LaraDock

LaraDock 和Laravel Homestead 类似,只不过运行在Docker 而非Vagrant 中。LaraDock 可以让我们在数秒之内轻松在 Docker 中运行 Laravel 应用。

LaraDock 致力于让开发过程变得简单,包含了一个已经预包装好的Docker映像以便为我们提供一流的开发环境而不需要再手动安装PHP、Nginx、MySQL、Redis以及其他运行Laravel应用可能要用到的软件或工具。

Docker vs Vagrant

说到这里,首先我们来了解什么是Docker:Docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的、可移植的、自给自足的容器。开发者在笔记本上编译测试通过的容器可以批量地在生产环境中部署,包括VMs(虚拟机)、bare metal、OpenStack 集群和其他的基础应用平台。

接下来我们来讨论为什么使用Docker而不是Vagrant:从时间上来看,Vagrant提供虚拟机需要数分钟,而Docker只需数秒;此外,从体量上来看,Vagrant提供的是完整的虚拟机,而Docker提供的是轻量级的虚拟容器,这些虚拟容器共享同一个内核并且允许在独立进程中运行。

LaraDock内置软件

LaraDock内置的Docker映像包含的软件:

  • Nginx + PHP
  • MySQL
  • Redis
  • Beanstalked
  • Data Volume

你可以编辑这些映像: https://github.com/LaraDock/docker-images

系统要求

  • Laravel(安装)
  • Docker Toolbox( 下载 )
  • Git( 下载 )
  • Composer( 下载 )

使用教程

1)安装任意版本Laravel,或者使用已存在的Laravel项目

2)在Laravel项目根目录下克隆LaraDock到 docker 目录:

git clone https://github.com/LaraDock/laradock.git docker

3)安装完Docker Toolbox后,将其安装目录放到系统路径,然后查看Docker IP地址:

  • 如果你使用的是Linux:IP地址默认是 127.0.0.1 ,因为容器可以直接在本地运行
  • 如果你使用的是Mac或Windows并且使用的是 docker-machine :输入 docker-machine ip {vm-name-here} 命令查看(默认IP是 192.168.99.100 )
  • 如果你使用的是Mac或Windows并且使用的是 boot2docker :输入 boot2docker ip 命令查看

这里我们使用的是Windows环境并使用 docker-machine ,查看IP地址方式如下:

可见IP地址为 192.168.99.100 。

4)在 hosts 文件中映射Docker IP到 laravel.dev :

xxx.xxx.xxx.xxx laravel.dev
Copy after login

不要忘了将 xxx.xxx.xxx.xxx 替换成你的Docker IP地址,这里我的IP地址是192.168.99.100。

5)在上述第二步新创建的 docker 目录中,打开 docker-compose.yml 文件将 xxx.xxx.xxx.xxx 替换成你的Docker IP地址。

6)打开Laravel项目的 .env 文件,将 DB_HOST 、 REDIS_HOST 设置为 laravel.dev :

DB_HOST=laravel.devREDIS_HOST=laravel.dev
Copy after login

如果在 .env 中没有找到变量 REDIS_HOST ,到数据库配置文件 config/database.php 中将 127.0.0.1 替换成 laravel.dev :

'redis' => [    'cluster' => false,    'default' => [        'host' => 'laravel.dev',        'port' => 6379,        'database' => 0,    ],],
Copy after login

如果你想要使用Redis作为缓存/Session驱动,打开 .env 文件将 CACHE_DRIVER 和 SESSION_DRIVER 设置为 redis :

CACHE_DRIVER=redisSESSION_DRIVER=redis
Copy after login

7)最后在 docker 目录下使用如下命令运行容器:

docker-compose up
Copy after login

如果你想要在后台运行容器可以使用 docker-compose up -d 命令:

注意:第一次运行上述命令时会花费5分钟左右(取决于你的网速)下载映像到本地。

8)在浏览器中访问 http://laravel.dev 。

更多使用介绍可参考官方文档: http://laradock.github.io/laradock/

GitHub地址

LaraDock: https://github.com/LaraDock/laradock

Docker-Images: https://github.com/LaraDock/docker-images

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

See all articles