Traefik not routing to other containers - wordpress

I've set up Traefik and Portainer on my server running Ubuntu 20.04 that is in my front room (I used this guide and this one, but didn't set up the default IP whitelist in the second tutorial as I want it to be a publicly accessible webserver). Both apps work and appear to be using HTTPS. I can manage and create containers in Portainer.
To test out my configuration, I added two containers - MySQL and Wordpress. I added in the Traefik labels from the above tutorials like when I set up Traefik, and I set the Wordpress container's domain name in Portainer, but whenever I try to access the Wordpress site at that domain, I get a Bad Gateway error (just the words 'Bad Gateway', not even a status code).
I'm not sure where I've gone wrong. Here are my configuration files:
traefik.yml:
api:
dashboard: true
entryPoints:
http:
address: ":80"
https:
address: ":443"
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false
file:
filename: /config.yml
version: '3'
services:
traefik:
image: traefik:v2.0
container_name: traefik
restart: unless-stopped
security_opt:
- no-new-privileges:true
networks:
- proxy
ports:
- 80:80
- 443:443
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data/traefik.yml:/traefik.yml:ro
- ./data/acme.json:/acme.json
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.entrypoints=http"
- "traefik.http.routers.traefik.rule=Host(`traefik.mywebsite.com`)"
- "traefik.http.middlewares.traefik-auth.basicauth.users=michael:$$apr1$$.m1mfSB0$$6Ypx6rfih8y.vHkNQe9rJ0"
- "traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https"
- "traefik.http.routers.traefik.middlewares=traefik-https-redirect"
- "traefik.http.routers.traefik-secure.entrypoints=https"
- "traefik.http.routers.traefik-secure.rule=Host(`traefik.mywebsite.com`)"
- "traefik.http.routers.traefik-secure.middlewares=traefik-auth"
- "traefik.http.routers.traefik-secure.tls=true"
- "traefik.http.routers.traefik-secure.tls.certresolver=http"
- "traefik.http.routers.traefik-secure.service=api#internal"
networks:
proxy:
external: true
certificatesResolvers:
http:
acme:
email: me#myemail.com
storage: acme.json
httpChallenge:
entryPoint: http
config.yml:
http:
middlewares:
https-redirect:
redirectScheme:
scheme: https
docker-compose.yml:
version: '3'
services:
traefik:
image: traefik:v2.0
container_name: traefik
restart: unless-stopped
security_opt:
- no-new-privileges:true
networks:
- proxy
ports:
- 80:80
- 443:443
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data/traefik.yml:/traefik.yml:ro
- ./data/acme.json:/acme.json
- ./data/config.yml:/config.yml:ro
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.entrypoints=http"
- "traefik.http.routers.traefik.rule=Host(`traefik.mywebsite.com`)"
- "traefik.http.middlewares.traefik-auth.basicauth.users=michael:$$apr1$$.m1mfSB0$$6Ypx6rfih8y.vHkNQe9rJ0"
- "traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https"
- "traefik.http.routers.traefik.middlewares=traefik-https-redirect"
- "traefik.http.routers.traefik-secure.entrypoints=https"
- "traefik.http.routers.traefik-secure.rule=Host(`traefik.mywebsite.com`)"
- "traefik.http.routers.traefik-secure.middlewares=traefik-auth"
- "traefik.http.routers.traefik-secure.tls=true"
- "traefik.http.routers.traefik-secure.tls.certresolver=http"
- "traefik.http.routers.traefik-secure.service=api#internal"
networks:
proxy:
external: true
Wordpress/MySQL docker-compose.yml:
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: admin
WORDPRESS_DB_PASSWORD: password
WORDPRESS_DB_NAME: wordpressdb
volumes:
- wordpress:/var/www/html
networks:
- proxy
labels:
- "traefik.enable=true"
- "traefik.http.routers.wordpress.entrypoints=http"
- "traefik.http.routers.wordpress.rule=Host(`myblog.com`)"
- "traefik.http.routers.wordpress.middlewares=https-redirect#file"
- "traefik.http.routers.wordpress-secure.entrypoints=https"
- "traefik.http.routers.wordpress-secure.rule=Host(`myblog.com`)"
- "traefik.http.routers.wordpress-secure.tls=true"
- "traefik.http.routers.wordpress-secure.tls.certresolver=http"
- "traefik.http.routers.wordpress-secure.service=wordpress"
- "traefik.http.services.wordpress.loadbalancer.server.port=9000"
- "traefik.docker.network=proxy"
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: username
MYSQL_PASSWORD: password
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db:/var/lib/mysql
networks:
- proxy
labels:
- "traefik.enable=true"
- "traefik.http.routers.mysql.entrypoints=http"
- "traefik.http.routers.mysql.middlewares=https-redirect#file"
- "traefik.http.routers.mysql-secure.entrypoints=https"
- "traefik.http.routers.mysql-secure.tls=true"
- "traefik.http.routers.mysql-secure.tls.certresolver=http"
- "traefik.http.routers.mysql-secure.service=mysql"
- "traefik.http.services.mysql.loadbalancer.server.port=9000"
- "traefik.docker.network=proxy"
volumes:
wordpress:
db:
networks:
proxy:
external: true
I can provide the Portainer docker-compose.yml file too if needed, but I don't really think it's necessary. Any help here would be great!

For network connectivity between the different applications you must create the network in one of your applications. I would do that in your traefik docker-compose.yml
Meaning, that in your traefik compose file you must NOT specify the proxy network as external, because you create it internally in that application like this:
networks:
proxy:
In your Wordpress/MySQL docker-compose.yml you must specify a name for the external network like this:
networks:
proxy:
external:
name: "traefik_proxy"
When you create a new application using compose, everything in the application gets a prefix, that is the directoryname in which the compose file is placed.
Meaning the above example only works if your traefik compose file is placed in a directory named "traefik"
This should fix your issue with connectivity.

Related

Problem with using APM in asp.net core application

I'm using asp.net core and docker and the goal is to use Elastic APM, here is my configuration:
Program.cs:
app.UseAllElasticApm(builder.Configuration);
appsettings.json:
"ElasticApm": {
"ServiceName": "Appraisal360APMSerivce",
"LogLevel": "verbose",
"ServerUrl": "http://localhost:8200",
"apm-server-secret-token": "",
"TransactionSampleRate": 1.0
}
docker-compose file:
version: '3.4'
services:
apm-server:
image: docker.elastic.co/apm/apm-server:7.15.2
ports:
- 8200:8200
- 6060:6060
volumes:
- ./apm-server.yml:/usr/share/kibana/config/apm-server.yml
environment:
- output.elasticsearch.hosts=["http://elasticsearch:9200"]
networks:
- elastic
command: >
apm-server -e
-E apm-server.rum.enabled=true
-E apm-server.host=0.0.0.0:8200
-E setup.kibana.host=kibana:5601
cap_drop:
- ALL
cap_add:
- CHOWN
- DAC_OVERRIDE
- SETGID
- SETUID
logging:
driver: 'json-file'
options:
max-size: '200m'
max-file: '50'
elasticsearch:
container_name: elasticsearch
image: elasticsearch:8.5.0
ports:
- 9200:9200
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
environment:
- discovery.type=single-node
- xpack.security.enabled=true
networks:
- elastic
kibana:
container_name: kibana
image: kibana:8.5.0
volumes:
- ./kibana.yml:/usr/share/kibana/config/kibana.yml
environment:
- XPACK_MONITORING_ENABLED=true
- XPACK_MONITORING_COLLECTION_ENABLED=true
- XPACK_SECURITY_ENABLED=true
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
ports:
- 5601:5601
networks:
- elastic
elastic-agent:
image: docker.elastic.co/beats/elastic-agent:8.5.0
container_name: elastic-agent
restart: always
user: root # note, synthetic browser monitors require this set to `elastic-agent`
environment:
- fleet-server-es=http://localhost:9200
- fleet-server-service-token=*****
- fleet-server-policy=fleet-server-policy
networks:
elastic:
driver: bridge
volumes:
elasticsearch-data:
my container is up and running without error
now the problem is here that fleet server does not find any connection like what u see in the picture:
i would be thankful if there is any help

nextcloud in docker-compose not reachable

I am using docker compose on my raspberry pi. In the yaml file I have a nextcloud and nginx (for outside communication). But as my raspberry pi is in my private network, I want to have also a direct connection for my immobile setup.
Something like an ip: 192.168.0.100:1080
What I have tried:
version: '3'
volumes:
nextcloud-data:
nextcloud-db:
npm-data:
npm-ssl:
npm-db:
networks:
frontend:
backend:
services:
nextcloud-app:
image: nextcloud
restart: always
ports:
- "1080:80"
- "1443:443"
volumes:
- nextcloud-data:/var/www/html
environment:
- MYSQL_PASSWORD=replace-with-secure-password
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=nextcloud-db
networks:
- frontend
- backend
nextcloud-db:
image: mariadb
restart: always
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
volumes:
- nextcloud-db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=replace-with-secure-password
- MYSQL_PASSWORD=replace-with-secure-password
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
networks:
- backend
npm-app:
image: jc21/nginx-proxy-manager:latest
restart: always
ports:
- "80:80"
- "81:81"
- "443:443"
environment:
- DB_MYSQL_HOST=npm-db
- DB_MYSQL_PORT=3306
- DB_MYSQL_USER=npm
- DB_MYSQL_PASSWORD=replace-with-secure-password
- DB_MYSQL_NAME=npm
volumes:
- npm-data:/data
- npm-ssl:/etc/letsencrypt
networks:
- frontend
- backend
npm-db:
image: jc21/mariadb-aria:latest
restart: always
environment:
- MYSQL_ROOT_PASSWORD=replace-with-secure-password
- MYSQL_DATABASE=npm
- MYSQL_USER=npm
- MYSQL_PASSWORD=replace-with-secure-password
volumes:
- npm-db:/var/lib/mysql
networks:
- backend
Additional information
The docker is started with docker-compose up -d
Nginx is not configured yet
Nextcloud is not configured yet
But with this approach the address 192.168.0.100:1080 does not resolve. Is this the right way to do it or why is the port 1080 not reachable?

traefik doesn't redirect http to https

I'm new in traefik, and couldn't understand why it doesn't redirect.
I saw a lot ways how to do redirect , and this one pretty match for me, because i want, that redirect works on the all routers.
Especially I don't want to write redirect to labels of every router
docker-compose.yml
services:
traefik:
image: traefik:v2.5
container_name: traefik
restart: unless-stopped
security_opt:
- no-new-privileges:true
ports:
- 80:80
- 443:443
- 8082:8082
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data/traefik.yml:/traefik.yml:ro
- ./data/custom/:/custom/:ro
- ./data/acme.json:/acme.json
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.rule=Host(`traefik.example.com`)"
- "traefik.http.routers.traefik.tls=true"
- "traefik.http.routers.traefik.tls.certresolver=letsEncrypt"
- "traefik.http.routers.traefik.service=api#internal"
- "traefik.http.services.traefik-traefik.loadbalancer.server.port=888"
- "traefik.http.middlewares.traefik-auth.basicauth.users=admin:$$apr1$$yTyey7a2$$CDmIjg/aratMfqENIHcQW1"
- "traefik.http.routers.traefik.middlewares=traefik-auth"
traefik.yml
api:
dashboard: true
entryPoints:
http:
address: ":80"
http:
redirections:
entryPoint:
to: https
scheme: https
permanent: true
https:
address: ":443"
metrics:
address: ":8082"
metrics:
prometheus:
entryPoint: metrics
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false
file:
directory: /custom
watch: true
certificatesResolvers:
letsEncrypt:
acme:
email: postmaster#example.com
storage: acme.json
#caServer: "https://acme-staging-v02.api.letsencrypt.org/directory"
httpChallenge:
entryPoint: http
A few months ago I have configured a reverse proxy with Traefik, basically, I have an authentication server and an API. Traefik redirects the traffic toward the authentication server if the request url has the auth path prefix and toward the API if the request url has the api path prefix. Here you go all my configuration using docker-compose.yaml:
version: '3'
services:
reverse-proxy:
image: traefik:v2.5
container_name: selling-point-reverse-proxy
ports:
- 80:80
- 8080:8080
volumes:
# Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
command:
# Enables the web UI
- --api.insecure=true
# Tells Traefik to listen to docker
- --providers.docker
# Creates a new entrypoint called web
- --entrypoints.web.address=:80
# Disable container exposition
- --providers.docker.exposedByDefault=false
# Traefik matches against the container's labels to determine whether to create any route for that container
- --providers.docker.constraints=Label(`traefik.scope`,`selling-point`)
networks:
- selling-point
api:
image: selling-point-api
container_name: selling-point-api
build:
context: ./selling-point-api
labels:
# Tells Traefik where to redirect the request if the url has the specified prefix
- traefik.http.routers.api.rule=PathPrefix(`/api`)
# Attaches a middleware for forwarding the authentication
- traefik.http.routers.api.middlewares=forward-auth,latency-check
# Attaches entrypoints
- traefik.http.routers.api.entrypoints=web
# Exposes container
- traefik.enable=true
# Matcher for creating a route
- traefik.scope=selling-point
# Creates a service called selling-point-api
- traefik.http.services.selling-point-api.loadbalancer.server.port=3000
# Attach the container to a service
- traefik.http.routers.api.service=selling-point-api
# Creates circuit breaker middleware
- traefik.http.middlewares.latency-check.circuitbreaker.expression=LatencyAtQuantileMS(50.0) > 100
volumes:
- ./selling-point-api/src:/app/src
networks:
- selling-point
environment:
WAIT_HOSTS: mysql:3306
DATABASE_URL: mysql://root:huachinango#mysql:3306/selling_point
NODE_ENV: development
auth:
image: selling-point-auth
container_name: selling-point-auth
build:
context: ./selling-point-auth
labels:
# Tells Traefik where to redirect the request if the url has the specified prefix
- traefik.http.routers.auth.rule=PathPrefix(`/auth`)
# Creates a forward auth middleware
- traefik.http.middlewares.forward-auth.forwardauth.address=http://auth:3000/auth/authorize
# Attaches entrypoints
- traefik.http.routers.auth.entrypoints=web
# Exposes container
- traefik.enable=true
# Matcher for creating a route
- traefik.scope=selling-point
# Creates a service called selling-point-auth
- traefik.http.services.selling-point-auth.loadbalancer.server.port=3000
# Attach the container to a service
- traefik.http.routers.auth.service=selling-point-auth
# Attaches a circuit breaker middleware
- traefik.http.routers.auth.middlewares=latency-check
environment:
WAIT_HOSTS: mysql:3306
IGNORE_ENV_FILE: 'true'
DATABASE_URL: mysql://root:huachinango#mysql:3306/selling_point
PASSWORD_SALT: $$2b$$10$$g0OI8KtIE3j6OQqt1ZUDte
NODE_ENV: development
volumes:
- ./selling-point-auth/src:/app/src
networks:
- selling-point
mysql:
image: mysql:5
environment:
MYSQL_ROOT_PASSWORD: huachinango
MYSQL_DATABASE: selling_point
networks:
- selling-point
volumes:
- mysql-db:/var/lib/mysql
volumes:
mysql-db:
networks:
selling-point:
name: selling-point
driver: bridge

Setting up docker Multisite configuration (VIPGo Environment)

I am trying to create a multisite docker configuration and I am not sure how to proceed with the existing docker-compose.yml that I use. I have already it up so that I can spin up as many sites as I want using a network. Here is the shared docker-compose.yml for reference.
version: "3.3"
services:
photon:
image: "chriszarate/photon:latest"
mysql:
image: "mariadb:10.2"
container_name: "mysql-database"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: "wordpress"
MYSQL_ROOT_PASSWORD: ""
ports:
- "3306:3306"
restart: always
volumes:
- type: volume
source: dbdata
target: "/var/lib/mysql"
volume:
nocopy: true
#- "./sql:/docker-entrypoint-initdb.d"
adminer:
image: adminer
restart: always
ports:
- 8080:8080
proxy:
image: "jwilder/nginx-proxy:alpine"
container_name: "proxy"
environment:
HSTS: "off"
HTTPS_METHOD: "nohttps"
ports:
- "80:80"
- "443:443"
volumes:
- "//var/run/docker.sock:/tmp/docker.sock:ro"
- "./certs/self-signed:/etc/nginx/certs:ro"
- "./conf/nginx-proxy.conf:/etc/nginx/conf.d/proxy.conf:ro"
networks:
default:
external:
name: shared
volumes:
dbdata: {}
And here is the one that I use for sites.
version: "3.3"
services:
wordpress:
container_name: "wp"
image: "wordpress:${WP_VERSION:-4.9.7}-php${PHP_VERSION:-7.2}-apache"
environment:
VIRTUAL_HOST: "${DOCKER_DEV_DOMAIN:-project.test}"
WORDPRESS_DB_HOST: "mysql"
WORDPRESS_DB_NAME: "wordpress"
WORDPRESS_DB_PASSWORD: ""
WORDPRESS_DB_USER: "root"
external_links:
- mysql
volumes:
- "wp:/var/www/html:rw"
- "./certs/ca-root/ca.crt:/tmp/certs/root.crt:ro"
- "./conf/php-local.ini:/usr/local/etc/php/conf.d/local.ini:ro"
- "./conf/wp-local-config.php:/usr/local/etc/php/autoprepend.php:ro"
- "./src/vip-go-mu-plugins:/var/www/html/wp-content/mu-plugins"
- "./src/site1/client-mu-plugins:/var/www/html/wp-content/client-mu-plugins"
- "./src/site1/images:/var/www/html/wp-content/images"
- "./src/site1/languages:/var/www/html/wp-content/languages"
- "./src/site1/plugins:/var/www/html/wp-content/plugins"
- "./src/site1/private:/var/www/html/wp-content/private"
- "./src/site1/themes:/var/www/html/wp-content/themes"
- "./src/site1/vip-config:/var/www/html/wp-content/vip-config"
wp-cli:
container_name: "wp-cli"
image: "wordpress:cli-php${PHP_VERSION:-7.2}"
environment:
- APACHE_RUN_USER="www-data"
- APACHE_RUN_GROUP="www-data"
external_links:
- mysql
volumes:
- "wp:/var/www/html:rw"
- "./bin/install-wp.sh:/usr/local/bin/install-wp:ro"
- "./conf/php-local.ini:/usr/local/etc/php/conf.d/local.ini:ro"
- "./conf/wp-local-config.php:/usr/local/etc/php/autoprepend.php:ro"
- "./src/vip-go-mu-plugins:/var/www/html/wp-content/mu-plugins"
- "./src/site1/client-mu-plugins:/var/www/html/wp-content/client-mu-plugins"
- "./src/site1/images:/var/www/html/wp-content/images"
- "./src/site1/languages:/var/www/html/wp-content/languages"
- "./src/site1/plugins:/var/www/html/wp-content/plugins"
- "./src/site1/private:/var/www/html/wp-content/private"
- "./src/site1/themes:/var/www/html/wp-content/themes"
- "./src/site1/vip-config:/var/www/html/wp-content/vip-config"
networks:
default:
external:
name: shared
volumes:
wp: {}
This setup works fine for one site (any other sites I spin up when I make copies of the folder) and it replicates the environment that VIP Go has. But I am not sure what changes will be needed to make this work with multisite environment as each site will have a different folder when docker is spun up.
Any ideas?
TIA
Note: multisites will be different sites and not subdomains when it's set up in production so I need to keep it that way and not set up subdomains

multiple docker compose container - single ip

I have this application.
How can I assign a single ip-address to the web-service and use the database within?
version: "2"
services:
web:
image: kartoffeltoby/typo3:latest
hostname: localhost
container_name: web
ports:
- 80:80
link:
- db:database
volumes:
- ./www/:/var/www/
environment:
- DOCROOT=/var/www/web
- PAGESPEED=Off
db:
image: mysql:5.6
hostname: database
volumes:
- ./DB/:/var/lib/mysql/
- ./db/:/var/tmp/db
environment:
- MYSQL_ROOT_PASSWORD=passwort
The solution is:
network_mode: service:web
version: "2"
services:
typo3:
image: kartoffeltoby/typo3:latest
hostname: axdbw.vagrant
container_name: typo3
volumes:
- ./www/:/var/www/
environment:
- DOCROOT=/var/www/web
- PAGESPEED=Off
networks:
mynet:
ipv4_address: 172.16.47.14
db:
image: mysql:5.6
volumes:
- ./DB/:/var/lib/mysql/
- ./db/:/var/tmp/db
environment:
- MYSQL_ROOT_PASSWORD=passwort
network_mode: service:web
networks:
mynet:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.16.47.0/24
There is no reason to use a specific IP. The solution can be as simple as this:
version: "3"
services:
typo3:
image: kartoffeltoby/typo3:latest
container_name: typo3
networks:
- mynet
db:
image: mysql:5.6
network_mode: "service:typo3"
networks:
mynet:
driver: bridge
This will place the db container onto the same IP as the typo3 container. Beware of possible port collisions.
In my use-case, I had to avoid nasty cross origin errors. Hosting the database on the same IP as my frontend container helped get around those issues.

Resources