What I would like to do
I'm trying to understand how to add 2 different services with Traefik on the same virtual server with Docker Compose. I have chosen a java / tomcat server and a php / apache server but you can choose 2 different services.
What I would like to achieve
I would like to view the content of my website in java on https://java.localhost and the content of my website in php on https://php.localhost.
Both websites projected individually with Traefik work.
What I get
When I try to put the 2 services on the same virtual server, on the browser I get '404 page not found'. In the Ubuntu shell I get the following code:
Creating container-java-eb ... done
Creating container-php-eb ... done
Attaching to container-java-eb, container-traefik-eb, container-php-eb
container-php-eb | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.30.0.4. Set the 'ServerName' directive globally to suppress this message
container-php-eb | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.30.0.4. Set the 'ServerName' directive globally to suppress this message
container-php-eb | [Mon Jul 11 14:14:14.942848 2022] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.53 (Debian) PHP/8.1.8 configured -- resuming normal operations
container-php-eb | [Mon Jul 11 14:14:14.942939 2022] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
container-traefik-eb | time="2022-07-11T14:14:15Z" level=info msg="Configuration loaded from flags."
container-java-eb |
container-java-eb | . ____ _ __ _ _
container-java-eb | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
container-java-eb | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
container-java-eb | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
container-java-eb | ' |____| .__|_| |_|_| |_\__, | / / / /
container-java-eb | =========|_|==============|___/=/_/_/_/
container-java-eb | :: Spring Boot :: (v2.7.1)
container-java-eb |
container-java-eb | 2022-07-11 14:14:16.794 INFO 1 --- [ main] springbootdemo.Application : Starting Application v0.0.1 using Java 11.0.15 on e0a6fc7ff3f1 with PID 1 (/appfolder/spring-boot-jar-docker-demo-(http).jar started by root in /appfolder)
container-java-eb | 2022-07-11 14:14:16.804 INFO 1 --- [ main] springbootdemo.Application : No active profile set, falling back to 1 default profile: "default"
container-java-eb | 2022-07-11 14:14:19.024 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
container-java-eb | 2022-07-11 14:14:19.036 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
container-java-eb | 2022-07-11 14:14:19.037 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.64]
container-java-eb | 2022-07-11 14:14:19.138 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
container-java-eb | 2022-07-11 14:14:19.139 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2179 ms
container-java-eb | 2022-07-11 14:14:19.903 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
container-java-eb | 2022-07-11 14:14:19.920 INFO 1 --- [ main] springbootdemo.Application : Started Application in 4.168 seconds (JVM running for 5.869)
My Docker Compose code
docker-compose.yml
version: "3.9"
services:
traefik:
build: ./traefik
image: image-traefik-eb:v.1.0
container_name: container-traefik-eb
command:
- --log.level=INFO
- --log.filePath=/data-log/traefik.log
- --log.format=json
- --api.insecure
- --api.dashboard
- --providers.docker
- --providers.docker.exposedbydefault=false
- --entrypoints.web.address=:80
- --entrypoints.web.http.redirections.entryPoint.to=websecure
- --entrypoints.web.http.redirections.entrypoint.scheme=https
- --entrypoints.websecure.address=:443
- --entrypoints.websecure.http.tls=true
- --entrypoints.websecure.http.tls.certresolver=leresolver
- --entrypoints.websecure.http.tls.domains.main=localhost
- --entrypoints.websecure.http.tls.domains.sans=*.localhost
- --certificatesresolvers.leresolver.acme.tlsChallenge=true
- --certificatesresolvers.leresolver.acme.email=localhost@gmail.com
- --certificatesresolvers.leresolver.acme.caServer=https://acme-staging-v02.api.letsencrypt.org/directory
- --certificatesresolvers.leresolver.acme.storage=/letsencrypt/acme.json
- --log.filePath=/traefik-log/traefik.log
- --log.format=json
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./volumes/data-letsencrypt/:/letsencrypt
- ./volumes/data-log/:/data-log/
ports:
- 8080:8080
- 80:80
- 443:443
java:
build: ./java
image: image-java-eb:v.1.0
container_name: container-java-eb
labels:
traefik.enable: 'true'
traefik.http.routers.training.rule: Host(`java.localhost`)
traefik.http.routers.training.tls.certresolver: leresolver
volumes:
- ./volumes/data-java:/appfolder
restart: on-failure
php:
build: ./php-apache
image: image-php-eb:v.1.0
container_name: container-php-eb
labels:
traefik.enable: 'true'
traefik.http.routers.training.rule: Host(`php.localhost`)
traefik.http.routers.training.tls.certresolver: leresolver
volumes:
- ./volumes/data-php:/var/www/html
restart: on-failure
index.php
<!doctype html>
<html lang="it">
<head><title>Ciao Mondo!</title></head>
<body>
<h1>Ciao Mondo!</h1>
<p>Questa è una semplice pagina PHP.</p>
<h2>Versione di PHP in uso:</h2>
<?php phpinfo(); ?>
</body>
</html>
Dockerfile
FROM php:8.1-apache