Multiple Laravel Docker Containers with Custom URL's in Windows Environment

Multiple Laravel Docker Containers with Custom URL's in Windows Environment

Developing with Docker on Windows usually means urls like localhost:8080 or localhost:8081. What if we want multiple Laravel instances running at the same time with custom URL's so we can access it via http://my-app-4.test

Using a reverse proxy and Nginx this is possible with Docker.

Installation

  1. Install Docker Desktop
  2. Clone this repository to your Windows environment https://github.com/rbaskam/nwi-docker-multi-app.
  3. Create a Docker Network with the command docker network create nginx-proxy

The structure of the folder will be:

+-- nginx-proxy
| +-- docker-compose.yml
| +-- certs
+-- my-app.test
+-- my-app-2.test
+-- my-app-3.test

Hosting

Click Start and type Notepad, right click and open as Administrator.

Click File->Open-> C:\Windows\System32\drivers\etc\hosts In hosts add 127.0.0.1 my-app-2.test at the bottom.

 

Laravel App (Each New App)

In the root of the folder run git clone git@github.com:rbaskam/docker-multi-app-base.git my-app-2.test

cd my-app-2.test and delete the .git from root.

cd src and run rm README.md

To create a new laravel project run composer create-project laravel/laravel . or use your own

cd ..

In the my-app-2.test folder edit the docker-compose.yml change all the container_name (8 ish of them) to something unique e.g nginx_four to nginx_five 

Then change all the ports to something unique only the first part so - 3306:3306 becomes - 3307:3306

In the same file change the virtual host to match your app

environment:

      VIRTUAL_HOST: my-app-2.test

In the root of my-app-2.test run  docker-compose up -d --build navigate to  my-app-2.test navigate in your browser to see the laravel app.

Create a self-signed SSL certificate for a custom domain

To create the certificates, we use the create-ssl-certificate command line tool (by Christian Alfoni). First we install it globally with npm i -g create-ssl-certificate.

go to /nginx-proxy/certs/.

issue a certificate with create-ssl-certificate --hostname my-app --domain local.

Rename the files ssl.crt and ssl.key to my-app-2.test.crt and my-app-2.test.key.

Trust the certificate

Follow this Guide to add it to your local dev area

 

Categories: Category 1