# Use Traefik as a reverse proxy for a MySQL docker container

**URL:** https://community.traefik.io/t/use-traefik-as-a-reverse-proxy-for-a-mysql-docker-container/24178
**Category:** Traefik v3 (latest)
**Tags:** docker, tcp
**Created:** [August 26, 2024, 7:12pm UTC](https://community.traefik.io/t/use-traefik-as-a-reverse-proxy-for-a-mysql-docker-container/24178 "2024-08-26T19:12:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![R0land013](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/r0land013/32/9239_2.png) [@R0land013](https://community.traefik.io/u/R0land013)
#### Post date: [August 26, 2024, 7:12pm UTC](https://community.traefik.io/t/use-traefik-as-a-reverse-proxy-for-a-mysql-docker-container/24178/1 "2024-08-26T19:12:59Z")

</div>

Hi there. I have a docker container with MariaDB exposing port 3306, and a traefik instance on the host system exposing port 3305 and using TLS. I want to redirect the traffic from traefik to the container of MariaDB, so Traefik gets rid of the TLS negotiation and pass plain TCP to MariaDB container. I setup the static and dynamic config files, but when I tried to connect using the approach of the port 3305 the program waits a lot and finally traefik prints this:

```auto
ERR github.com/traefik/traefik/v3/pkg/server/router/tcp/postgres.go:32 > Error while Peeking first byte error="read tcp...

```

this is my static config file:

```auto
log:
  level: TRACE
  filePath: "/home/myuser/access.log"

entryPoints:
     mariadb:
       address: ":3305"

providers:
  file:
    filename: "/home/myuser/dynamic.yaml"

```

and this is my dynamic config file:

```auto
tcp:
  routers:
    mysql-router:
      entryPoints:
        - mariadb
      rule: "HostSNI(`*`)"
      service: mariadb
      tls: {}

  services:
    mariadb:
      loadBalancer:
        servers:
          - address: "127.0.0.1:3306"

```

I have searched in the community and Internet but I can not solve this.

---

<div class="post-metadata">

### Author: ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)
#### Post date: [August 26, 2024, 7:47pm UTC](https://community.traefik.io/t/use-traefik-as-a-reverse-proxy-for-a-mysql-docker-container/24178/2 "2024-08-26T19:47:49Z")

</div>

How do you provide the TLS cert to Traefik?

---

<div class="post-metadata">

### Author: ![R0land013](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/r0land013/32/9239_2.png) [@R0land013](https://community.traefik.io/u/R0land013)
#### Post date: [August 27, 2024, 5:03pm UTC](https://community.traefik.io/t/use-traefik-as-a-reverse-proxy-for-a-mysql-docker-container/24178/3 "2024-08-27T17:03:01Z")

</div>

Hi @bluepuma77. My error I did not copied all the text. This is my complete dynamic config file. Thanks for your time.

```auto
tcp:
  routers:
    mysql-router:
      entryPoints:
        - mariadb
      rule: "HostSNI(`*`)"
      service: mariadb
      tls: {}

  services:
    mariadb:
      loadBalancer:
        servers:
          - address: "127.0.0.1:3306"

tls:
  certificates:
    - certFile: /home/myuser/mariadb_certificate/certificate.crt
      keyFile: /home/myuser/mariadb_certificate/private.key

```

---

<div class="post-metadata">

### Author: ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)
#### Post date: [August 27, 2024, 5:19pm UTC](https://community.traefik.io/t/use-traefik-as-a-reverse-proxy-for-a-mysql-docker-container/24178/4 "2024-08-27T17:19:22Z")

</div>

Try to set the cert as default in the TLS section ([doc](https://doc.traefik.io/traefik/https/tls/#default-certificate)).

Make sure your cert is officially valid or load the required parts in the sql client.
