Traefik acts as a reverse proxy, automatically routing requests to local domains to the corresponding containers.
- Traefik operation: Traefik runs as a Docker Compose container and listens for incoming HTTP/HTTPS requests.
- Request routing: Traefik analyzes the
Hostheaders in the requests and, based on the rules defined indocker-compose.yml, redirects the requests to the necessary PHP application containers. - Domain management: Traefik allows the use of convenient local domains (e.g.,
myapp.loc) instead oflocalhost:portfor accessing applications.
-
Configuration placement: It is recommended to place the
traefik/folder separately from the PHP application project. -
Traefik execution: Run the Traefik container using Docker Compose:
docker compose up -d
-
Network check: After execution, the
traefik_defaultnetwork should appear. All PHP application containers that should be accessible via Traefik must be connected to this network.-
If the network is not created automatically, create it manually:
docker network create traefik_default --label "com.docker.compose.network=default"
-
-
Automatic start: Traefik is configured to start automatically when Docker or the computer is restarted (
restart: always). If necessary, change this parameter indocker-compose.yml.
- Adminer: A web interface for managing MariaDB databases. Available at
https://adminer.loc.- Add an entry to the
hostsfile:127.0.0.1 adminer.loc. - In the Adminer login window:
Server: the name of the MariaDB container.Username/Password: credentials from.envor default values fromdocker-compose.yml.
- Add an entry to the
- MailHog: A tool for intercepting and viewing outgoing emails from PHP applications. Available at
http://localhost:8025.- Email redirection is configured in the
php.inifile (.docker/php-fpm/app.dev.ini).
- Email redirection is configured in the
-
mkcert installation: Install the
mkcertutility (https://github.com/FiloSottile/mkcert) to generate local SSL certificates. -
Certificate generation: Generate certificates for local domains:
mkcert -cert-file certs/local-cert.pem -key-file certs/local-key.pem "localhost" "*.localhost" "adminer.loc" "myapp.loc" "yourdomain.loc"
- List all necessary domains separated by a space.
- Wildcard certificates for root domains (
*.loc) may not work in some browsers.
-
Makefile usage: The
Makefilealready has agen-certcommand for convenient certificate generation. Edit it by adding the necessary domains to the list:gen-cert: mkcert -cert-file certs/local-cert.pem -key-file certs/local-key.pem "localhost" "*.localhost" "adminer.loc" "myapp.loc" "yourdomain.loc"- Then run the
make gen-certcommand.
- Then run the
-
Traefik restart: After generating the certificates, you need to restart the Traefik container for it to pick up the new certificates, using the
make restartcommand:make restart
-
HTTPS access: After restarting the container, local sites will be accessible via HTTPS without warnings about an untrusted certificate in the browser.