Local development environment with multiple hosts running through an Nginx proxy
- Set up an SSH key
- Install Docker Desktop
- Clone this repository
git clone git@github.com:nickdenardis/docker-environment.git ~/Sites/docker/nginx-proxy
- Copy the environment variables
cd ~/Sites/docker/nginx-proxy && cp .env.example .env
- Update the environment variables
.env
- Install optional aliases
aliases
- Install the hosts in
/etc/hosts
Example host local.dock
cd ~/Sites/docker/nginx-proxy/ssl
openssl req -x509 -nodes -new -sha512 \\n -days 365 -newkey rsa:4096 -keyout ca.key \\n -out ca.pem -subj "/C=US/CN=MY-CA"
openssl x509 -in ca.pem -text -noout
openssl x509 -outform pem -in ca.pem -out ca.crt
cat > v3.ext <<-EOF\nauthorityKeyIdentifier=keyid,issuer\nbasicConstraints=CA:FALSE\nkeyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment\nsubjectAltName = @alt_names \n[alt_names]\n# Local hosts\nDNS.1 = localhost\nDNS.2 = 127.0.0.1\nDNS.3 = ::1 \n# List your domain names here\nDNS.4 = local.dock\nDNS.5 = *.local.dock\nEOF
openssl req -new -nodes -newkey rsa:4096 \\n -keyout local.dock.key -out local.dock.csr \\n -subj "/C=US/ST=Michign/L=Detroit/O=Local/CN=local.dock"
Build the PHP FPM images
cd ~/Sites/docker/nginx-proxy/
docker build -t php-80-fpm:v1 ./php-80-fpm
docker build -t php-73-fpm:v1 ./php-73-fpm
docker build -t php-55-fpm:v1 ./php-55-fpm
Start the Nginx proxy, MariaDB, Redis and the docker network
cd ~/Sites/docker/nginx-proxy
docker compose up -d
Start the main and sub sites in one command
docker-compose -f docker-compose.yml -f php-80/docker/docker-compose.yml up -d
Go into a sub directory and the docker directory
cd ~/Sites/docker/nginx-proxy/php-80/docker
docker compose up -d
Do a composer install
cd ~/Sites/docker/nginx-proxy/php-80/
docker run --rm -it -v $PWD:/app composer install
Update the .env
file with the database and redis information from the nginx config
DB_CONNECTION=mysql
DB_HOST=example_app-db
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
Install the node modules
docker run --rm -it -v "$PWD":/usr/src/app -w /usr/src/app node npm install
Build the site
docker run --rm -it -v "$PWD":/usr/src/app -w /usr/src/app node npm run dev
View the sites
https://php80.local.dock
cd ~/Sites/docker/nginx-proxy/php-80/docker
docker compose down
cd ~/Sites/docker/nginx-proxy
docker compose down
Run the 'composer' container and map the current directory to the /app
directory where it runs:
docker run --rm -it -v $PWD:/app composer create-project --prefer-dist laravel/laravel laravelproject
Update the .env
file with the database and redis information
DB_HOST=db_server
DB_PORT=3306
DB_DATABASE=laravelproject
DB_USERNAME=test_user
DB_PASSWORD=test_pass
CACHE_DRIVER=redis
REDIS_HOST=redis
Install the npm packages by using the node image and mapping the current directory to the working directory
docker run --rm -it -v "$PWD":/usr/src/app -w /usr/src/app node npm install
d:exec
Get into a Bash command prompt in the container (debug)d:composer require laravel/breeze --dev
Run a composer command in the containerd:artisan cache:clear
Run an artisan command in the containerd:phpunit
Run the PHPUnit tests in the containerd:node npm install
Run node commnds on the directory
The php.ini
file specifies how to send mail()
:
sendmail_path = "/usr/local/bin/mhsendmail --smtp-addr=mailhog:1025 -f noreply@localhost"
Viewing the outgoing mail:
- Dynamic DNS based on the folder name
- Use Apache for the webserver at each host instead of Nginx or this one or this one
- Move the php.ini files into the built fpm containers instead of per-site
- Figure out how to trap outgoing mail with Mailhog
- PHP 5.5 image and perhaps redis in the regular apt-get
- Use the
.env
file for all the configs