# Access to mysql containers

**URL:** <https://community.traefik.io/t/access-to-mysql-containers/5753>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [April 28, 2020, 6:37am UTC](https://community.traefik.io/t/access-to-mysql-containers/5753 "2020-04-28T06:37:45Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbrioski](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@mbrioski](https://community.traefik.io/u/mbrioski)\
**Post date:** [April 28, 2020, 6:37am UTC](https://community.traefik.io/t/access-to-mysql-containers/5753/1 "2020-04-28T06:37:45Z")

</div>

Hallo,  
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: [https://github.com/zioDocker/DockerDevelopmentOnMac/issues/4](https://github.com/zioDocker/DockerDevelopmentOnMac/issues/4)

Thanks

---

<div class="post-metadata">

**Author:** ![SantoDE](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/santode/32/393_2.png) [@SantoDE](https://community.traefik.io/u/SantoDE)\
**Post date:** [April 28, 2020, 12:46pm UTC](https://community.traefik.io/t/access-to-mysql-containers/5753/2 "2020-04-28T12:46:16Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![mbrioski](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@mbrioski](https://community.traefik.io/u/mbrioski)\
**Post date:** [April 28, 2020, 1:15pm UTC](https://community.traefik.io/t/access-to-mysql-containers/5753/3 "2020-04-28T13:15:59Z")

</div>

Hi,  
you can use this docker-compose example:  
[https://github.com/zioDocker/DockerDevelopmentOnMac/blob/master/docker-compose-examples/magento2.yml](https://github.com/zioDocker/DockerDevelopmentOnMac/blob/master/docker-compose-examples/magento2.yml)

And the configuration is the one you can find in [https://github.com/zioDocker/DockerDevelopmentOnMac/blob/master/configuration/traefik/traefik2.2.toml](https://github.com/zioDocker/DockerDevelopmentOnMac/blob/master/configuration/traefik/traefik2.2.toml)

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.

---

<div class="post-metadata">

**Author:** ![SantoDE](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/santode/32/393_2.png) [@SantoDE](https://community.traefik.io/u/SantoDE)\
**Post date:** [April 28, 2020, 1:21pm UTC](https://community.traefik.io/t/access-to-mysql-containers/5753/4 "2020-04-28T13:21:40Z")

</div>

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 [https://docs.traefik.io/routing/providers/docker/](https://docs.traefik.io/routing/providers/docker/) and try agian 🙂

---

<div class="post-metadata">

**Author:** ![mbrioski](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@mbrioski](https://community.traefik.io/u/mbrioski)\
**Post date:** [April 28, 2020, 1:52pm UTC](https://community.traefik.io/t/access-to-mysql-containers/5753/5 "2020-04-28T13:52:01Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![SantoDE](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/santode/32/393_2.png) [@SantoDE](https://community.traefik.io/u/SantoDE)\
**Post date:** [April 28, 2020, 2:07pm UTC](https://community.traefik.io/t/access-to-mysql-containers/5753/6 "2020-04-28T14:07:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mbrioski](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@mbrioski](https://community.traefik.io/u/mbrioski)\
**Post date:** [April 28, 2020, 2:08pm UTC](https://community.traefik.io/t/access-to-mysql-containers/5753/7 "2020-04-28T14:08:08Z")

</div>

ok, it makes sense 🙂

This is the configuration that i have tried but doesn't work: [https://github.com/zioDocker/DockerDevelopmentOnMac/blob/issue/%234-traefik-mysql/docker-compose-examples/magento2.yml](https://github.com/zioDocker/DockerDevelopmentOnMac/blob/issue/%234-traefik-mysql/docker-compose-examples/magento2.yml)

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

---

<div class="post-metadata">

**Author:** ![SantoDE](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/santode/32/393_2.png) [@SantoDE](https://community.traefik.io/u/SantoDE)\
**Post date:** [April 29, 2020, 7:14am UTC](https://community.traefik.io/t/access-to-mysql-containers/5753/8 "2020-04-29T07:14:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mbrioski](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@mbrioski](https://community.traefik.io/u/mbrioski)\
**Post date:** [April 29, 2020, 7:31am UTC](https://community.traefik.io/t/access-to-mysql-containers/5753/9 "2020-04-29T07:31:32Z")

</div>

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

```auto
labels:
        - "traefik.enable=true"
        - "traefik.tcp.routers.db.rule=HostSNI(`*`)"
        - "traefik.tcp.services.db.loadbalancer.server.port=3306"
        - "traefik.tcp.routers.db.entrypoints=mysql"

```

and when i try to connect i get this:

 ![Screenshot 2020-04-29 at 09.29.47](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/8/821c9aaed352b6d258539df31fd4d7fa00fc5699.jpeg)

---

<div class="post-metadata">

**Author:** ![SantoDE](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/santode/32/393_2.png) [@SantoDE](https://community.traefik.io/u/SantoDE)\
**Post date:** [April 29, 2020, 12:23pm UTC](https://community.traefik.io/t/access-to-mysql-containers/5753/10 "2020-04-29T12:23:48Z")

</div>

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

```auto
version: '3.2'

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

```

![image](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/d/d3acc605f049b80f80ad1a728f7acb5e2a83e8dc.png)

---

<div class="post-metadata">

**Author:** ![mbrioski](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@mbrioski](https://community.traefik.io/u/mbrioski)\
**Post date:** [April 29, 2020, 12:46pm UTC](https://community.traefik.io/t/access-to-mysql-containers/5753/11 "2020-04-29T12:46:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Fuhrmann](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/fuhrmann/32/2264_2.png) [@Fuhrmann](https://community.traefik.io/u/Fuhrmann)\
**Post date:** [July 6, 2020, 1:55pm UTC](https://community.traefik.io/t/access-to-mysql-containers/5753/12 "2020-07-06T13:55:32Z")

</div>

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.
