Access to mysql containers

i have created a repository to optimise development on Mac, using Traefik to handle multiple projects.
I'm not able to make the correct configuration inside traefik and docker-compose file, in order to access to mysql containers from any tool.
This is the issue and the repository on github:


Can you please post the exact Traefik configuration and docker-compose file? I'm trying to find it on your repo but I wasn't succesfull :slight_smile:

you can use this docker-compose example:

And the configuration is the one you can find in

But u can use any mysql container: the point is, how to access with a tool to a docker container that run under Traefik on port 3306.

Thank u very much.

Yeah okay.

But in that example, you're not configuring your mariadb container to proxied through Traefik, like you're doing with your web container.

I suggest you to lookup Traefik dynamic configuration on docker and try agian :slight_smile:

Yes i know that the configuration is missing...
i have tried, looking into the documentation and set up a configuration but i was not able to make it works... so i asked :slight_smile:

Then, I'd like, that you post your "broken" configuration and we'll try to fix it :wink:

ok, it makes sense :slight_smile:

This is the configuration that i have tried but doesn't work:

Container is visible inside Traefik and without error but if i try to connect via any tool, i get connection refused.

If I remember correctly, the tcp connection of mysql is not making use of TLS and thus, no SNI. Therefore, you can't use the HostSNI(my-db) matcher like that. You rather have to use it as a wildcard HostSNI(*) and connect to the Traefik Container on Port 3306, as this is the port of your mysql entrypoint.

Does it make sense?

mmm not sure if it makes sense but at the end it doesn't work.
I have tried this conf:

        - "traefik.enable=true"
        - "traefik.tcp.routers.db.rule=HostSNI(`*`)"
        - ""
        - "traefik.tcp.routers.db.entrypoints=mysql"

and when i try to connect i get this:

Not sure what you're trying, but I'm able to connect through a mysql cli just fine with that compose file

version: '3.2'

    image: 'traefik:2.2'
      - "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.mysql.address=:3306"
      - "80:80"
      - "3306:3306"
      - "8080:8080"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    image: 'mariadb:10.2'
      - "traefik.enable=true"
      - "traefik.tcp.routers.db.rule=HostSNI(`*`)"
      - ""
      - "traefik.tcp.routers.db.entrypoints=mysql"
      - MYSQL_DATABASE=test
      - MYSQL_USER=test
      - MYSQL_PASSWORD=test


Thanks u very much for your effort... it works now.....
I was so stupid... after having change the rule... i forgot to expose again the port 3306....

Just one question: is there a way to handle two database connections having the same params?
Technically if u have 2 docker-compose files, with same db containers and same environment variables, in docker they work because they run on two different services.
The problem comes when u try to connect to them using Traefik, because using the same wildcad(*) for both, Traefik has not chance to distinguish them.
i.e. try to use your configuration for two projects...

Thank u again

1 Like

From what I understand in this case you must have 1 port to 1 database. If you want to access 2 databases, you must have 2 ports (2 entrypoints), each one for a different database.