How to install the laravel development environment with docker
- 2020-06-07 05:40:24
- OfStack
When I looked at the installation section of the laravel framework's official documentation, I found that there was a huge amount of software to install, and I guess there were a lot of complicated configurations. The official recommendation was to use the Laravel Homestead virtual machine for installation, but I thought, since there is something as good as docker, why not use it?
Docker vs Vagrant
Why use Docker instead of Vagrant: In terms of time, Vagrant provides the virtual machine in minutes, while Docker only takes seconds; In addition, in terms of volume, Vagrant provides full virtual machines, while Docker provides lightweight virtual containers that share a single kernel and allow running in separate processes.
The environment setup steps are as follows:
1. First download the ES22en-ES23en image from Docker hub
docker pull laraedit/laraedit
2. Create the laravel directory with the docker command
docker run --name laravel -p 8088:80 -v /Users/berylqliu/Workspace/laravelTest:/var/www/html/app laraedit/laraedit
Parameter description:
--name: Name of the service started -ES38en: Port mapping, native 8088 port mapping container 80 port -ES39en: directory mount, native directory: container directory -ES40en: If this parameter is added, the background starts the servicelaraedit opens 80, 443, 3306, 6379 port by default, so if you want direct external access, use the -ES45en parameter.
3. Start docker shell
docker exec -it laravel /bin/bash
laravel is the above -name specified, under docker shell, you can operate the database, etc.
4. Create 1 application in the container, note and mount directory 1
cd /var/www/html/
laravel new app
Or:
cd /var/www/html/app/
laravel new blog
Move the file under blog to app and delete blog. Just note that the mount directory maps to 1
5. If the container exits, start the container:
docker start laravel
The next command to start docker shell:
docker exec -it -v /Users/berylqliu/Workspace/laravelTest:/var/www/html/app laravel /bin/bash
Then you can see the homepage of http://localhost:8088/. Other related docker commands can be learned on your own.