├── .editorconfig
├── .env.example
├── .github
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── bug_report.yml
│ └── config.yml
├── PULL_REQUEST_TEMPLATE.md
└── SECURITY.md
├── .gitignore
├── .vscode
└── extensions.json
├── CHANGELOG.md
├── LICENSE
├── README.md
├── compose.yaml
├── config
└── Caddyfile.example
└── images
├── bmc-button.svg
├── firefox-settings.png
├── mac-keychain-access.png
├── programming.svg
├── qr-code.png
└── social-preview.png
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | insert_final_newline = true
7 | indent_style = space
8 | indent_size = 2
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
13 | indent_size = 4
14 |
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
1 | #--------------------------------------------------------------------------
2 | # If you want to change the container name, network name or
3 | # the source code folder, you can create a DotEnv file
4 | # and override the Docker Compose variables.
5 | #
6 | # You can run the following command in the terminal
7 | # to create your DotEnv file.
8 | #
9 | # cp .env.example .env
10 | #--------------------------------------------------------------------------
11 |
12 | #--------------------------------------------------------------------------
13 | # Docker env
14 | #--------------------------------------------------------------------------
15 |
16 | # The project name. | default: reverse_proxy
17 | APP_NAME="reverse_proxy"
18 |
19 | #--------------------------------------------------------------------------
20 | # Container env
21 | #--------------------------------------------------------------------------
22 |
23 | # The Caddy Server Docker container name. | default: reverse_proxy
24 | CONTAINER_NAME="${APP_NAME}"
25 |
26 | #--------------------------------------------------------------------------
27 | # Network env
28 | #--------------------------------------------------------------------------
29 |
30 | # Map the Admin API port to the host port. | default: 2019
31 | ADMIN_API_PORT=2019
32 |
33 | # The Docker network for the containers. | default: reverse_proxy
34 | NETWORK_NAME="reverse_proxy"
35 |
36 | #--------------------------------------------------------------------------
37 | # Volume env
38 | #--------------------------------------------------------------------------
39 |
40 | # The app container data volume. | default: reverse_proxy_data
41 | CONTAINER_VOLUME_DATA_NAME="${CONTAINER_NAME}_data"
42 |
43 | # The app container config volume. | default: reverse_proxy_config
44 | CONTAINER_VOLUME_CONFIG_NAME="${CONTAINER_NAME}_config"
45 |
--------------------------------------------------------------------------------
/.github/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Code of Conduct
2 |
3 | The ***Docker Reverse Proxy*** code of conduct is based on [The Ruby Community Conduct Guidelines](https://www.ruby-lang.org/en/conduct/).
4 |
5 | This document provides community guidelines for a respectful, productive, and collaborative place for any person who
6 | is willing to contribute to the ***Docker Reverse Proxy*** project. It applies to all “collaborative space”, which is
7 | defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.).
8 |
9 | - Participants will be tolerant of opposing views.
10 | - Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
11 | - When interpreting the words and actions of others, participants should always assume good intentions.
12 | - Behaviour which can be reasonably considered harassment will not be tolerated.
13 |
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Docker Reverse Proxy Contributing Guide
2 |
3 | Thanks for your interest in contributing to ***Docker Reverse Proxy***! Before
4 | submitting your contribution, please make sure to take a moment and read
5 | through the following guidelines:
6 |
7 | - [Code of Conduct](#coc)
8 | - [Got a Question or Problem](#question)
9 | - [Submitting an Issue](#issue)
10 | - [Submitting a Pull Request (PR)](#pr)
11 |
12 | ## Code of Conduct
13 |
14 | Help us keep development for ***Docker Reverse Proxy*** open and inclusive.
15 | Please read and follow our [Code of Conduct](CODE_OF_CONDUCT.md).
16 |
17 | ## Got a Question or Problem?
18 |
19 | Do not open issues for general support questions as we want to keep GitHub
20 | issues for bug reports and feature requests. Instead, we recommend using the
21 | [GitHub Discussions](https://github.com/luisaveiro/docker-reverse-proxy/discussions)
22 | space.
23 |
24 | ## Submitting an Issue
25 |
26 | Before you submit an issue, please search the issue tracker or
27 | [GitHub Discussions](https://github.com/luisaveiro/docker-reverse-proxy/discussions)
28 | space, maybe an issue for your problem already exists and the discussion might
29 | inform you of workarounds readily available.
30 |
31 | You can file new issues by selecting from our
32 | [new issue templates](https://github.com/luisaveiro/docker-reverse-proxy/issues/new/choose)
33 | and filling out the issue template.
34 |
35 | ## Submitting a Pull Request (PR)
36 |
37 | **Please ask first before starting work on any significant new features.**
38 |
39 | It's never a fun experience to have your pull request declined after investing
40 | a lot of time and effort into a new feature. To avoid this from happening, we
41 | request that contributors create an
42 | [issue](https://github.com/luisaveiro/docker-reverse-proxy/issues/new/choose)
43 | to first discuss any significant new features.
44 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: [luisaveiro]
4 | custom: ['https://www.buymeacoffee.com/luisaveiro']
5 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.yml:
--------------------------------------------------------------------------------
1 | name: Bug report
2 | description: Create a report to help us improve
3 | title: '[Bug]:
'
4 | labels: ['bug']
5 | assignees:
6 | - luisaveiro
7 | body:
8 | - type: markdown
9 | attributes:
10 | value: Thanks for taking the time to fill out this bug report! Provide a general summary of the issue in the Title above.
11 | - type: checkboxes
12 | attributes:
13 | label: Is there an existing issue for this?
14 | description: Please search to see if an issue already exists for the bug you encountered.
15 | options:
16 | - label: I have searched the existing issues
17 | required: true
18 | - type: textarea
19 | attributes:
20 | label: Description
21 | description: Provide a more detailed introduction to the issue and why you consider it a bug.
22 | validations:
23 | required: true
24 | - type: textarea
25 | attributes:
26 | label: Expected Behaviour
27 | description: A clear and concise description of what you expected to happen.
28 | validations:
29 | required: true
30 | - type: textarea
31 | attributes:
32 | label: Current Behaviour
33 | description: Tell us what happens instead of the expected behaviour.
34 | validations:
35 | required: true
36 | - type: textarea
37 | attributes:
38 | label: Possible Solution
39 | description: Not obligatory, but suggest a fix or reason for the bug.
40 | validations:
41 | required: false
42 | - type: textarea
43 | attributes:
44 | label: Steps to Reproduce
45 | description: Provide an unambiguous set of steps to reproduce this bug. Include code to reproduce, if relevant.
46 | placeholder: |
47 | 1.
48 | 2.
49 | 3.
50 | 4.
51 | validations:
52 | required: false
53 | - type: textarea
54 | attributes:
55 | label: Screenshots or logs
56 | description: |
57 | If applicable, add screenshots or logs to help explain your problem.
58 |
59 | Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in.
60 | validations:
61 | required: false
62 | - type: textarea
63 | attributes:
64 | label: Additional Context
65 | description: |
66 | How has this bug affected you? What were you trying to accomplish?
67 | Providing context helps us come up with a solution that is most useful in the real world.
68 | validations:
69 | required: false
70 | - type: textarea
71 | attributes:
72 | label: Environment
73 | description: |
74 | Include as many relevant details about the environment in which you experienced the bug.
75 |
76 | examples:
77 | - **OS**: MacOS 13.5.2
78 | - **Docker Reverse Proxy version**: 1.0.0
79 | value: |
80 | - OS:
81 | - Docker Reverse Proxy version:
82 | render: markdown
83 | validations:
84 | required: false
85 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 | contact_links:
3 | - name: Ask a Question
4 | url: https://github.com/luisaveiro/docker-reverse-proxy/discussions/categories/q-a
5 | about: Ask the community for help
6 | - name: Feature Request
7 | url: https://github.com/luisaveiro/docker-reverse-proxy/discussions/categories/ideas
8 | about: Share ideas for new features
9 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | #### Purpose
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | ---
12 | #### Related Issue
13 |
14 |
15 |
16 |
17 |
18 | Please link to the issue here:
19 |
20 | ---
21 | #### Types of changes
22 |
23 |
24 | - [ ] Bug fix (non-breaking change which fixes an issue).
25 | - [ ] New feature (non-breaking change which adds functionality).
26 | - [ ] Breaking change (fix or feature that would cause existing functionality to change).
27 | - [ ] Refactoring.
28 | - [ ] Other (documentation).
29 |
30 | ---
31 | #### Are breaking changes introduced?
32 |
33 |
34 |
35 | ---
36 | #### Development Checklist
37 |
38 |
39 |
40 | - [ ] My code follows our coding standards.
41 | - [ ] I have read the **CONTRIBUTING** document.
42 | - [ ] I have updated the **CHANGELOG** accordingly.
43 | - [ ] I have updated the **README**, if necessary.
44 |
--------------------------------------------------------------------------------
/.github/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | **PLEASE DON'T DISCLOSE SECURITY-RELATED ISSUES PUBLICLY, [SEE BELOW](#reporting).**
4 |
5 | I take security on ***Docker Reverse Proxy*** project very seriously. This means
6 | including features to protect developer's environments.
7 |
8 | ## Disclaimer
9 |
10 | ***Docker Reverse Proxy*** has been developed to run Caddy in a local Docker
11 | environment. If you wish to use Caddy on your system, you can follow the follow
12 | the [Installation Guide](https://caddyserver.com/docs/install).
13 |
14 | ## Reporting a Vulnerability
15 |
16 | If you discover a security vulnerability within ***Docker Reverse Proxy***
17 | `docker-compose.yml` file, please
18 | send an e-mail to Luis Aveiro via [support@luisaveiro.io](support@luisaveiro.io)
19 | instead of using the issue tracker. All security vulnerabilities will be
20 | promptly addressed.
21 |
22 | ## Supported Versions
23 |
24 | Please ensure you have the latest updated version of ***Docker Reverse Proxy***.
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .env
2 | .DS_Store
3 | Caddyfile
4 | /certificate-authority/*
5 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": [
3 | "zamerick.vscode-caddyfile-syntax"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 | All notable changes to `luisaveiro/docker-reverse-proxy` will be documented in this file.
3 |
4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6 |
7 | ## [Unreleased]
8 |
9 | ## [v1.0.1] 2025-03-13
10 | ### Removed
11 | - The obsolete 'version' attribute in Docker Compose file.
12 |
13 | ## [v1.0.0] 2023-06-18
14 | ### Added
15 | - Caddy REST API port is included and configured in the Docker Compose file.
16 |
17 | ### Changed
18 | - Updated Docker Compose file to allow better customisation with environment variables.
19 | - Update DotEnv example file formatting.
20 |
21 | ## [v0.2.0] 2022-10-12
22 | ### Added
23 | - TLS configuration in `Caddyfile` example file to enable Caddy HTTPS support.
24 | - Developer-friendly comments for environment variables in the DotEnv example file.
25 | - "Trusting Caddy certificate authority" steps in Readme.
26 |
27 | ### Changed
28 | - Renamed Docker Compose file to follow compose specifications.
29 | - Readme to adopt Compose V2 specifications.
30 |
31 | ## [v0.1.2] 2022-05-03
32 | ### Fixed
33 | - Connection refuse when triggering the `caddy reload` command.
34 |
35 | ## [v0.1.1] 2021-12-13
36 | ### Fixed
37 | - Docker Compose not creating volumes.
38 |
39 | ## [v0.1.0] - 2021-12-01
40 | ### Added
41 | - Docker Compose YAML file.
42 | - Caddyfile example file.
43 | - DotEnv example file.
44 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Luis Carlos Aveiro
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
31 |
32 | ## About
33 |
34 | This repository offers a simple approach to having [Caddy Server](https://caddyserver.com/)
35 | as a local reverse proxy for your [Docker](https://www.docker.com/) containers.
36 | Caddy Server is the first and only web server to use HTTPS automatically with
37 | no extra configuration or separate tooling required.
38 |
39 | **Why would you need a local reverse proxy?**
40 | With a hosts file, you can only map hostnames to IP addresses. Hosts file does
41 | not support mapping ports with IP addresses. You are unable to map multiple
42 | containers to hostnames.
43 |
44 | As a developer, you might be working on multiple Docker-based projects. We have
45 | all experienced the Docker container port binding failure message -
46 | *Bind for 0.0.0.0:80 failed: port is already allocated.*
47 |
48 | Or you are working on a multi-tenant application that requires tenants to log
49 | in on their subdomain. Developing locally can be challenging with this
50 | requirement.
51 |
52 | Having a reverse proxy you can assign domains or subdomains to your Docker
53 | containers without the need to worry about port binding failures or develop
54 | locally with a multi-tenant subdomain application.
55 |
56 | ## Disclaimer
57 |
58 | > [!IMPORTANT]
59 | > ***Docker Reverse Proxy*** is not affiliated with Stack Holdings
60 | GmbH or Docker, Inc and is not an official product from either company.
61 |
62 | "Caddy" is a registered trademark of Stack Holdings GmbH.
63 | "Docker" is a registered trademark of Docker, Inc.
64 |
65 | ***Docker Reverse Proxy*** has been developed to run Caddy in a local Docker
66 | environment. If you wish to use Caddy on your system, you can follow the follow
67 | the [Installation Guide](https://caddyserver.com/docs/install).
68 |
69 | ## Getting Started
70 |
71 | You will need to make sure your system meets the following prerequisites:
72 |
73 | - Docker Engine >= 20.10.00
74 |
75 | This repository utilizes [Docker](https://www.docker.com/) to run Caddy. So,
76 | before using ***Docker Reverse Proxy***, make sure you have Docker installed
77 | on your system.
78 |
79 | ## Download
80 |
81 | You can clone the latest version of ***Docker Reverse Proxy*** repository for
82 | macOS, Linux and Windows.
83 |
84 | ```bash
85 | # Clone this repository.
86 | $ git clone git@github.com:luisaveiro/docker-reverse-proxy.git --branch main --single-branch
87 | ```
88 |
89 | ## How To Use
90 |
91 | Below is the current directory structure for the ***Docker Reverse Proxy*** repository.
92 |
93 | ```
94 | .
95 | +-- config
96 | | +-- Caddyfile.example
97 | +-- .env.example
98 | +-- compose.yaml
99 | ```
100 |
101 | There are a few steps you need to follow before you can have Caddy set up and
102 | running as a reverse proxy for your Docker containers. I have outline the steps
103 | you would need to take to get started.
104 |
105 | #### 1. Update your hosts file
106 |
107 | You will need to modify your `/etc/hosts` file to include the hostnames entries.
108 | The hostname is the domain or subdomain you wish to direct traffic for a Docker
109 | container.
110 |
111 | The structure of the hostname entry must be your loopback IP Address
112 | (`127.0.0.1`) and domain/subdomain. For example:
113 |
114 | ```
115 | 127.0.0.1 domain.local
116 | ```
117 |
118 | > [!NOTE]
119 | > The hosts file **does not support wildcard** (`*`) for domains
120 | or subdomains. You will need to have an entry for each domain and subdomain you
121 | wish to use for the reverse proxy in your hosts file.
122 |
123 | #### 2. Create a Caddyfile
124 |
125 | Once you have added your domain/subdomain entry to your hosts file, you will
126 | need to create a `Caddyfile`. The Caddyfile is a convenient Caddy configuration
127 | format for humans.
128 |
129 | ***Docker Reverse Proxy*** includes a `Caddyfile.example` file in the config
130 | directory to help you get started. You can run the following command in the
131 | terminal to create your Caddyfile file.
132 |
133 | ```bash
134 | # Create Caddyfile from Caddyfile.example.
135 | $ cp config/Caddyfile.example config/Caddyfile
136 | ```
137 |
138 | #### 3. Add your site blocks to your Caddyfile
139 |
140 | Caddy supports various configurations, you can follow the
141 | [Caddy Documentation](https://caddyserver.com/docs/caddyfile) to learn more
142 | about the various configurations supported by Caddyfile.
143 |
144 | This readme will focus on the Caddyfile reverse proxy configuration
145 | (*with minimum configuration*). You will need to create a site block in the
146 | Caddyfile to match the domain entry of your hosts file.
147 |
148 | The `Caddyfile.example` file has an example of the structure of the site block.
149 |
150 | ```ini
151 | # HTTP site block
152 | :80 {
153 | reverse_proxy :
154 | }
155 |
156 | # HTTPS site block
157 | :443 {
158 | tls internal
159 | reverse_proxy :
160 | }
161 | ```
162 |
163 | Let's cover the the Caddyfile's structure:
164 |
165 | - **Site block**
166 | The site block defines the Caddy configuration for a given site address. You
167 | can identify a site block by the curly braces.
168 |
169 | - **Site address**
170 | The site address is the domain/subdomain entry which matches your hostname in
171 | your hosts file. Unlike your hosts file, Caddyfile supports port mapping.
172 |
173 | - **Directive**
174 | A directive is the Caddy instruction. Caddy has a variety of
175 | [directives](https://caddyserver.com/docs/caddyfile/directives). This is readme
176 | will focus on the [reverse_proxy](https://caddyserver.com/docs/caddyfile/directives/reverse_proxy)
177 | directive.
178 |
179 | - **Argument**
180 | The reverse_proxy argument is the upstream which Caddy will proxy. In our use
181 | case the upstream will be the Docker container name and the exposed port.
182 |
183 | - **TLS (HTTPS only)**
184 | The TLS directive is to configure HTTPS for the site block. By using the
185 | internal option, we are using Caddy's internal, locally-trusted CA to produce
186 | certificates for the site.
187 |
188 | Below is an example of a configured site block:
189 |
190 | ```ini
191 | # Personal website
192 | website.local:80 {
193 | reverse_proxy website_app:8080
194 | }
195 |
196 | # Personal website using HTTPS
197 | website.local:443 {
198 | tls internal
199 | reverse_proxy website_app:8080
200 | }
201 | ```
202 |
203 | #### 4. Start Caddy Docker container
204 |
205 | After you have configured your Caddyfile, you can start Caddy Docker container.
206 | ***Docker Reverse Proxy*** includes a `compose.yaml` file with Caddy
207 | pre-configured. You can run the following command:
208 |
209 | ```bash
210 | # Start Caddy Docker container
211 | $ docker compose up
212 |
213 | # Or start Caddy Docker container detached mode
214 | $ docker compose up -d
215 | ```
216 |
217 | Docker will create the Caddy container which is called `docker-reverse-proxy`.
218 | The container will be attached to a network called `reverse_proxy`.
219 |
220 | If you want to change the container name, network name or volume names, you can
221 | create a DotEnv file and override the Docker Compose variables. Below is an
222 | example of the DotEnv variables.
223 |
224 | ```ini
225 | #--------------------------------------------------------------------------
226 | # Docker env
227 | #--------------------------------------------------------------------------
228 |
229 | # The project name. | default: reverse_proxy
230 | APP_NAME="reverse_proxy"
231 |
232 | #--------------------------------------------------------------------------
233 | # Container env
234 | #--------------------------------------------------------------------------
235 |
236 | # The Caddy Server Docker container name. | default: reverse_proxy
237 | CONTAINER_NAME="${APP_NAME}"
238 |
239 | #--------------------------------------------------------------------------
240 | # Network env
241 | #--------------------------------------------------------------------------
242 |
243 | # Map the Admin API port to the host port. | default: 2019
244 | ADMIN_API_PORT=2019
245 |
246 | # The Docker network for the containers. | default: reverse_proxy
247 | NETWORK_NAME="reverse_proxy"
248 |
249 | #--------------------------------------------------------------------------
250 | # Volume env
251 | #--------------------------------------------------------------------------
252 |
253 | # The app container data volume. | default: reverse_proxy_data
254 | CONTAINER_VOLUME_DATA_NAME="${CONTAINER_NAME}_data"
255 |
256 | # The app container config volume. | default: reverse_proxy_config
257 | CONTAINER_VOLUME_CONFIG_NAME="${CONTAINER_NAME}_config"
258 |
259 | ```
260 |
261 | ***Docker Reverse Proxy*** includes a `.env.example` file to get you started.
262 | You can run the following command in the terminal to create your DotEnv file.
263 |
264 | ```bash
265 | # Create .env from .env.example.
266 | $ cp .env.example .env
267 | ```
268 |
269 | #### 5. Trusting Caddy certificate authority (CA)
270 |
271 | If you are not planning to use HTTPS for local development, you can skip this
272 | step.
273 |
274 | Caddy generates its own certificate authority (CA) and uses it to sign
275 | certificates. After Caddy's root CA is created, you will need to add the
276 | certificate to your local trust store. I have outline the steps you would need
277 | to take.
278 |
279 | > [!IMPORTANT]
280 | > Please ensure you have the latest update of the Caddy Docker image.
281 |
282 | Caddy container will create and mount a folder called `certificate-authority`.
283 | In this folder you will see certificate and key files. You will be installing
284 | the `root.crt` in your local trust store.
285 |
286 | Open the "Keychain Access" app and drag and drop the certificate into the
287 | "login" keychain. Open the certificate (it should be called something like
288 | "Caddy Local Authority") and configure it to "Always Trust", as shown below.
289 |
290 |
300 |
301 | > [!TIP]
302 | > Firefox has its own local trust store. You will be required to complete
303 | one additional step.
304 |
305 | In Firefox, type 'about:config' in the address bar. If prompted, accept any
306 | warnings. Set "security.enterprise_roots.enabled" as true.
307 |
308 |
309 |
310 |
314 |
315 |
316 | Firefox settings for local trust store.
317 |
318 |
319 | #### 6. Attach Docker containers to Caddy network
320 |
321 | Once Caddy container is up and running, you will need to configure your Docker
322 | containers by attaching the **reverse_proxy** network to your container(s),
323 | assign a name to the container and expose the port that Caddy will proxy.
324 |
325 | I have outlined the necessary configuration below both for Docker Compose and
326 | Docker CLI approach.
327 |
328 | **Docker Compose**
329 |
330 | In your Docker Compose file you need to define **reverse_proxy** as an external
331 | network. For each services you want to access via Caddy reverse proxy, you will
332 | need to add **reverse_proxy** as an attached network and define your exposed
333 | port.
334 |
335 | Below I have provided an example of a Docker Compose file configured to match
336 | the example site block in the Caddyfile.
337 |
338 | ##### **Caddyfile**
339 |
340 | ```ini
341 | # Personal website
342 | website.local:80 {
343 | reverse_proxy website_app:8080
344 | }
345 | ```
346 |
347 | ##### **Docker Compose**
348 |
349 | ```yaml
350 | version: '3.9'
351 |
352 | services:
353 | website:
354 | # Container name should be the same as in the Caddyfile.
355 | container_name: website_app
356 | image: nginx:alpine
357 | restart: unless-stopped
358 | # Expose the mapped port that Caddy will proxy.
359 | expose:
360 | - 8080
361 | # Add reverse_proxy as attached network.
362 | networks:
363 | - reverse_proxy
364 | volumes:
365 | - ./src:/usr/share/nginx/html
366 |
367 | networks:
368 | # Add reverse_proxy as an external network.
369 | reverse_proxy:
370 | external: true
371 | ```
372 |
373 | **Docker CLI**
374 |
375 | If you don't use Docker Compose, I have included an example of Docker CLI to
376 | start a container with the necessary configurations.
377 |
378 | ```bash
379 | $ docker run --rm --name=website_app --expose 8080 --network=reverse_proxy nginx:alpine
380 | ```
381 |
382 | ## FAQ
383 |
384 | **Q:** Can I configure Caddy via the REST API?
385 | **A:** Yes, You can access Caddy administration endpoints via HTTP by connect to
386 | http://localhost:2019. You can change the the API port in the DotEnv file.
387 |
388 | ```ini
389 | #--------------------------------------------------------------------------
390 | # Network env
391 | #--------------------------------------------------------------------------
392 |
393 | # Map the Admin API port to the host port. | default: 2019
394 | ADMIN_API_PORT=2019
395 | ```
396 |
397 | **Q:** If I change the Caddyfile, do I need to restart the Docker container?
398 | **A:** Yes, You will need to restart Caddy to allow the reverse proxy to reload
399 | changes in your configuration. There are two commands you can use to restart
400 | Caddy.
401 |
402 | According to the Caddy Docker Hub page, Caddy comes with a `caddy reload`
403 | command. You can run the following command to reload Caddy configuration:
404 |
405 | ```bash
406 | $ docker exec -w /etc/caddy docker-reverse-proxy caddy reload
407 | ```
408 |
409 | The working directory is set to `/etc/caddy` so Caddy can find your Caddyfile
410 | without additional arguments.
411 |
412 | Alternatively, you can restart the Docker container by using the following command.
413 |
414 | ```bash
415 | $ docker-compose restart
416 | ```
417 |
418 | ## Useful Tips
419 |
420 | [VSCode Caddyfile Syntax](https://marketplace.visualstudio.com/items?itemName=zamerick.vscode-caddyfile-syntax)
421 | is an extension for VSCode that adds syntax highlighting for Caddyfiles.
422 |
423 | ## Changelog
424 |
425 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
426 |
427 | ## Contributing
428 |
429 | I encourage you to contribute to ***Docker Reverse Proxy***! Contributions are
430 | what make the open source community such an amazing place to be learn, inspire,
431 | and create. Any contributions you make are **greatly appreciated**.
432 |
433 | Please check out the [contributing to Docker Reverse Proxy guide](.github/CONTRIBUTING.md)
434 | for guidelines about how to
435 | proceed.
436 |
437 | ## Security Vulnerabilities
438 |
439 | Trying to report a possible security vulnerability in ***Docker Reverse Proxy***?
440 | Please check out our [security policy](.github/SECURITY.md) for guidelines
441 | about how to proceed.
442 |
443 | ## Credits
444 |
445 | The illustration used in the project is from [unDraw (created by Katerina Limpitsouni)](https://undraw.co/).
446 | All product names, logos, brands, trademarks and registered trademarks are
447 | property of their respective owners.
448 |
449 | ## Sponsor
450 |
451 | Do you like this project? Support it by donating.
452 |
453 |
454 |
455 |
456 |
457 | ## License
458 |
459 | The MIT License (MIT). Please see [License File](LICENSE) for more information.
460 |
461 | ---
462 |
463 |