Commit 2632a652 authored by Shane A. Stillwell's avatar Shane A. Stillwell 🎯

Merge branch 'patch-1' into 'master'

Replacing work around to expose the host machines ip address inside the…

See merge request !1
parents 2dd764b7 dbe57c9b
......@@ -64,37 +64,13 @@ services:
- ./ssl:/etc/nginx/ssl
ports:
- 443:443
extra_hosts:
- "dockerhost:${LOCAL_IP}"
```
As you can see:
* We pull down the nginx image using the small linux alpine version.
* Then we mount some volumes inside the container, the `proxy.conf` file and the `ssl` folder that holds our certs.
* Next the configuration tells the container to listen on port 443 and forward internall to port 443
* **What is the `extra_hosts` configration?**
* Glad you asked, let's cover that in this next section
* Next the configuration tells the container to listen on port 443 and forward internal to port 443
### The localhost alias
The problem we encounter here is allowing the container to contact the host machine. Since Nginx is running inside the Docker container and your app is running outside of the docker container, locally on port 3000, the container needs to know how to reach the host machine.
> This is not as easy as it would appear.
There are several solutions to this. On a Mac, the best way I've found is to create an alias to localhost. Simply run this command will create an alias to locahost.
```
sudo ifconfig lo0 alias 172.16.123.1
```
On Windows, I'm not sure, sorry.
### Back to extra_hosts
Notice that I have a reference to `${LOCAL_IP}`? Well, I have an environment variable that is just `LOCAL_IP=172.16.123.1`. In the `docker-compose.yml` file we assign that IP to the hostname `dockerhost`.
> DANGER! However tempting, Do NOT name your environment variable `DOCKER_HOST`, you'll break your docker setup. The reader can investigate why or ping me for the answer.
Docker Compose files can utilize [environment variables](https://docs.docker.com/compose/environment-variables/), nifty. Moving on.
### The Nginx configuration
......@@ -111,7 +87,7 @@ server {
ssl_certificate_key ssl/cert.key;
location / {
proxy_pass http://dockerhost:3000;
proxy_pass http://host.docker.internal:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-HTTPS 'True';
......@@ -121,7 +97,7 @@ server {
In here you'll notice a few items of interest:
* We specify our cert and key as living in the `ssl/*` folder we mounted in our docker-compose.yml file
* We are proxy passing all traffic to `dockerhost:3000`, this will resolve to your localhost:3000 on your machine.
* We are proxy passing all traffic to `host.docker.internal:3000`, this will resolve to your localhost:3000 on your machine.
* The rest is just standard configuration for setting up Nginx as a proxy.
### Start your docker container
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment