Using Docker for Local Development: Installation, Configuration, and Usage
This article explains the common pain points of local development and provides a step‑by‑step guide on installing Docker, Docker‑Compose, and Laradock, configuring environment files, setting up Nginx and host entries, and running containers to create a consistent, portable development environment.
Before development you often face dependency issues, environment variables, port conflicts, and mismatched production environments. Docker solves these problems by packaging applications and their dependencies into portable containers.
What is Docker
Docker is an open‑source container engine that lets developers bundle their apps and dependencies into a portable container that can run on any Linux machine, providing a lightweight, high‑performance alternative to virtual machines.
Benefits of Docker for Local Development
Rapid trial of new technologies with a single command.
Unified development and production environments across Windows, macOS, and Ubuntu.
Lower memory usage and faster start‑up compared to VMs.
Easier demonstration of features without complex setup.
Installing Docker
On macOS download the dmg file, double‑click and drag to install. Windows follows a similar process.
https://hub.docker.com/search/?type=edition&offering=community&q=
Verify installation with docker version:
Client: Docker Engine - Community
Version: 18.09.0
API version: 1.39
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:47:43 2018
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.0
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:55:00 2018
OS/Arch: linux/amd64
Experimental: trueInstalling Docker‑Compose
After installing Docker, Docker‑Compose is included. Verify with:
➜ ~ docker-compose version
docker-compose version 1.23.2, build 1110ad01
docker-py version: 3.6.0
CPython version: 3.6.6
OpenSSL version: OpenSSL 1.1.0h 27 Mar 2018Downloading Laradock
Clone the Laradock repository:
git clone https://github.com/laradock/laradockConfiguring the .env File
Copy env-example to .env: cp env-example .env Adjust APP_CODE_PATH_HOST and APP_CODE_PATH_CONTAINER if needed.
Enable Xdebug by setting PHP_FPM_INSTALL_XDEBUG and WORKSPACE_INSTALL_XDEBUG to true.
Search the .env file for any additional configuration options.
Running Containers
From the Laradock directory run: docker-compose up -d nginx mysql This builds and starts nginx, php-fpm, workspace, mysql, and related services.
Configuring the Web Project
Update the Laravel .env with database credentials:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD=rootEnsure the database host uses the service name (e.g., mysql) rather than 127.0.0.1 or localhost.
Configuring Host File
Add a virtual domain to /etc/hosts:
127.0.0.1 blog.testConfiguring Nginx
Copy laravel.conf.example to blog.conf and edit server_name and root:
server {
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;
fastcgi_read_timeout 600;
include fastcgi_params;
}
}Accessing the Application
Open a browser and navigate to http://blog.test/ to see the Laravel application running inside Docker.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
