Using Laradock in Mac/Windows to build a Docker based Laravel development environment
brief introduction
Docker literacy
-
Complex environment management: From various OSs to various middleware to various apps, a product can be successfully released. As a developer, there are too many things to care about and difficult to manage. This problem is common in the software industry and needs to be faced directly. Docker can simplify the deployment of multiple application instances, such as Web applications, background applications, database applications, big data applications, such as Hadoop clusters, message queues, etc., which can be packaged into one image deployment. -
The arrival of the cloud computing era: the success of AWS has led developers to transfer applications to the cloud, and solved the hardware management problem. However, problems related to software configuration and management still exist. The emergence of Docker can help software developers broaden their minds and try new software management methods to solve this problem. -
Changes in virtualization means: in the cloud era, standard hardware is used to reduce costs, and virtualization means are used to meet the resource needs of users allocated on demand and ensure availability and isolation. However, in the opinion of Docker, both KVM and Xen are wasting resources, because users need an efficient running environment rather than OS. GuestOS wastes resources and is difficult to manage. The more lightweight LXC is more flexible and fast. -
LXC portability: LXC has existed in the Linux 2.6 kernel, but it was not designed for cloud computing at the beginning. It lacks standardized description means and container portability, which makes it difficult to distribute and manage the built environment. Docker has made substantive innovations on this issue.
-
Automatic packaging and publishing of Web applications; -
Automated testing and continuous integration and release; -
Deploy and adjust databases or other background applications in a service-oriented environment; -
Compile from scratch or extend the existing OpenShift or Cloud Foundry platform to build your own PaaS environment.
Docker installation
Note: The use of Docker under Windows requires the Hyper-V component to be enabled (it is recommended to use it in the native system, and Windows 10 Professional Edition is enabled by default. In addition, Docker for Windows Desktop is not supported in Windows 10 Home Edition). If you use Windows in VMware or Parallels virtual machines, you need to enable nested virtualization support in settings (Settings ->Processor and Memory ->Advanced Options ->Enable Virtualization Manager). If the virtual machine does not support this configuration or Hyper-V, You can try to install Docker ToolBox additionally to support the use of Docker (refer to Official Documents )。 My environment here is Mac+VMware Fusion+Windows 10 (virtual machine).
Configure Image Accelerator
Get started quickly
git clone https://github.com/Laradock/laradock.git
cp env-example .env
# If you need to change the sources (i.e. to China), set CHANGE_SOURCE to true CHANGE_SOURCE=true # Set CHANGE_SOURCE and UBUNTU_SOURCE option if you want to change the Ubuntu system sources.list file. UBUNTU_SOURCE=aliyun
docker-compose up -d nginx mysql redis
/tmp/sources.sh: not found
DB_HOST=mysql REDIS_HOST=redis QUEUE_HOST=beanstalkd
APP_CODE_PATH_HOST=../wwwroot/
server { listen 80; listen [::]:80; server_name blog.test; root /var/www/blog/public; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri /index.php =404; fastcgi_pass php-upstream; fastcgi_index index.php; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fixes timeouts fastcgi_read_timeout 600; include fastcgi_params; } location ~ /\.ht { deny all; } location /.well-known/acme-challenge/ { root /var/www/letsencrypt/; log_not_found off; } }
127.0.0.1 blog.test
docker-compose down docker-compose up -d nginx
Note: For more details, please refer to the official document: http://laradock.io/documentation/
Functional characteristics
-
It is easy to switch between different versions of PHP: 7.2, 7.1, 5.6, etc -
Choose databases freely: MySQL, Postgres, MariaDB, etc -
Run your own software: Memcached, HHVM, Beanstalkd, etc -
Each software runs in an isolated container: PHP-FPM, NGINX, PHP-CLI, etc -
Easily customize containers by editing Dockerfile File -
All images are extended from official images -
Preconfigured NGINX -
Laradock can be used in each project, or all projects can share one Laradock -
Easily install/uninstall software in containers using environment variables -
Clean and well structured Dockerfile -
Latest version of docker-compose file -
Everything is visible and editable -
Quickly build images
-
Database engine: MySQL - MariaDB - Percona - MongoDB - Neo4j - RethinkDB - MSSQL - PostgreSQL - Postgres PostGIS -
Database management tool: PhpMyAdmin - Administrator - PgAdmin -
Cache tool: Redis - Memcached - Aerospike -
Web server: NGINX - Apache2 - Caddy -
PHP compiler: PHP-FPM - HHVM -
Message queue: Beanstalkd - RabbitMQ - PHP Worker -
Queue manager: Beanstalkd Console - RabbitMQ Console -
Major powers: HAProxy - Certbot - Blackfire - Selenium - Jenkins - ElasticSearch - Kibana - Mailhog - Minio - Varnish - Swoole - Lavel Echo, etc -
Laradock also introduced the Workspace image as the development environment, which contains a rich and practical tool set: PHP CLI - Composer - Git - Linuxbrew - Node - V8JS - Gulp - SQLite - xDebug - Envoy - Deployer - Vim - Yarn - SOAP - Drush, etc
Docker or Vagrant
Note: The local development environment used by Xuejun for daily development is Laradock.