by Devin Yang
(This article was automatically translated.)

Published - 3 years ago ( Updated - 2 years ago )

If you are a new user, I suggest you use my latest environment phpenv instead.

https://github.com/DevinY/phpenv

The following is the old information
1. First, you need to have Docker installed on your Mac system, which is a necessary condition.

2. Add an alias to the .bash_profile of your home directory. The following is the Laravel installer using Dlaravel's Docker Image.
Is to execute the laravel installer in the container to install Laravel on the host side.

#D-Laravel's laravel installer
alias laravel='docker run --rm -v ${PWD}:/var/www/html -v ~/.dlaravel/cache:/home/dlaravel/.composer/cache -ti deviny/fpm:8.0.3 / home/dlaravel/.composer/vendor/bin/laravel'
#D-Laravel's Project mode simplified instructions
alias pj='bash dlaravel/console'

After setting the alias, remember to source ~/.bash_profile to make the alias take effect. If you are using zsh, you can also add it to ~/.zshrc in your home directory. Remember to change it ~/.zshrc.

Third, with the above bash, we can install Laravel without installing composer or php on the system.
Use the Laravel installer in Docker to install Laravel.

laravel new myapp

4. Since D-Larael needs to be executed in Project mode, we can download D-Laravel to the Laravel project through git. This example is myapp.

cd myapp
git clone https://github.com/DevinY/dlaravel.git

6. D-Laravel is not in project mode by default. We can ask D-Laravel to use the project mode settings through the alias pj.
In the folder of myapp, execute the following command, only need to execute once.

pj project



Seventh, after that, we can activate or close the project through up and down.

#Start the container
pj up
# close the container
pj down

8. The default D-Laravel project mode will use a random port

[+] Running 5/5
⠿ Network myapp_dlaravel_net Created 3.7s
⠿ Network myapp_default Created 3.7s
⠿ Container myapp_web_1 Started 6.4s
⠿ Container myapp_db_1 Started 4.2s
⠿ Container myapp_php_1 Started 7.0s
Do nothing
DB:
host:56264
Web:
http://myapp.test:56266
Password:
127.0.0.1 myapp.test

9. If you want the Project mode to use port 8080 fixedly, just adjust the docker-compose.yml in D-Laravel.

vi dlaravel/docker-compose.yml

In the docker-compose.yml file, add the original "80" and adjust it to "8080:80", leave the archive, as long as the host port on the left does not conflict, you can You can freely adjust the port you want.

version: '3.6'
services:
#=== web service ========================
web:
image: nginx
dns: 8.8.8.8
ports:
- "8080:80"
- "443"
volumes:
==Slightly==

11. Restart the container to see

pj restart

Twelve, if you are a user of D-Laravel, you guessed it, pj is the console bash.
Therefore, we can check with pj info, just like what we used to check with ./console info before.

pj info
D-Laravel is running in project mode.
/Users/devin/myapp/dlaravel/docker-compose-project.yml
DB:
host:56602
Web:
http://myapp.test:8080

You can see that the connection port of myapp has changed to 8080.
 

Tags: laravel docker

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments