This is a set of scripts that facilitates the use of https on a local host for any project you run in Docker.
- Prerequisites
- Nginx Proxy Installation
- Local HTTPS Certificates
- Setting up *.devenv.test
- Attaching your application to
nginx-proxy
- OS
- macOS
- Linux
- Windows 10
- Docker
Linux and macOS scripts assume bash (or a compatible shell) to be used. If you use another shell, please use its syntax if it differs from bash.
On Windows Powershell is used.
To get started with the local dev environment, you need to install and run the Nginx Proxy container, which DevEnv projects rely on.
-
To start, clone this repository and go to the
nginx-proxy
directory:git clone [email protected]:denisvmedia/devenv.git cd devenv/nginx-proxy
-
Then, create a new docker network:
docker network create nginx-proxy
-
Finally, run the nginx-proxy container:
docker-compose up --build -d
For the additional information on how nginx-proxy
works, please refer to
the original documentation.
Many functionalities of DevEnv are https only (e.g. push notifications). In order to be able of use those, we need to install an HTTPS certificate locally. mkcert is a simple zero-config tool to make locally trusted development certificates with any names you’d like.
-
Use the official documentation to install
mkcert
on your platform.After having
mkcert
installed we can create our local certificates. Since DevEnv uses multiple domains, we can generate a wildcard one:# change to nginx-proxy/certs - the folder where nginx-proxy expects the certificates cd devenv/nginx-proxy/certs # generate the certificates mkcert -cert-file=devenv.test.crt -key-file=devenv.test.key *.devenv.test
Where
devenv.test
is the domain, whichnginx-proxy
will listen to. If you want, you can configure your own domain indocker-compose.override.yml
. -
To make your system and browsers trust the newly generated certificates you should run the following:
mkcert -install
Now you have your local HTTPS certificate.
As a rule of thumb, don't touch your /etc/hosts
file as there are smarter ways
to solve a problem of development domains.
- Ubuntu 20.04
- Run
bash ubuntu2004-test-domain.sh
script (utilizesdnsmasq
andsystemd-resolved
).
- Run
- macOS
- Run
bash macos-test-domain.sh
script (utilizesdnsmasq
).
- Run
- Windows 10
- Run
powershell.exe -File windows-test-domain.ps1
(will run CoreDNS in Docker).
- Run
Check this link for a demo application that exposes an http endpoint that becomes visible to nginx-proxy. To test it first run this script:
cd sample-project
docker-compose up --build
Then navigate in your browser to this link.
If you did everything properly, you should see a "Hello World" page without any certificate issues.