Only able to connect to dockerized MySQL after logging in via Adminer

TL;DR: I’m only able to connect via SSH tunnel to MySQL/Percona (in Docker) after previously connecting (with the same credentials) via Adminer.


Goal

I want to use a dockerized SSH Server to expose a port and then tunnel into other containers like MySQL internally. The idea is to use SSH to secure the connection.

Setup

I’m using the following Docker containers:

  • linuxserver/openssh-server
  • Percona MySQL Server
  • Adminer (formerly phpMinAdmin), only used for testing currently

The SSH server is exposed to the internet and shares the Docker network with the MySQL Server. In addition, Adminer is exposed for testing currently:

  Exposed to outside                    
     │                                  
     │       Server/Docker Containers   
     │      ┌───────────────────────┐   
     │   ┌──┼─────────────────────┐ │   
     └►  │  │  SSH Server/Tunnel  │ │   
         └──┼───────────────────┬─┘ │   
            │ ┌─────────────────▼─┐ │   
            │ │ MySQL Server      │ │   
            │ └─────────────────▲─┘ │   
         ┌──┼───────────────────┴─┐ │   
     ┌─► │  │  Adminer/PHPMyAdmin │ │   
     │   └──┼─────────────────────┘ │   
     │      └───────────────────────┘   
     └─── Only exposed temporarily for testing

The Problem

For some reason, I’m only able to login to MySQL (via tunnel) from outside after a successful login via Adminer. This is reproducable. Here is what I’m doing:

  • On the server start Docker containers:
    • docker compose up to start SSH container
    • docker compose up to start MySQL Server (+ Adminer) containers
  • Use MySQL client HeidiSQL (from my local computer) to login.
    • Receive error: Access denied for user 'root'@'172.18.0.2' (using password: YES)
  • Open Adminer in my web browser (exposed to the internet).
    • Login, Server: percona-mysql-server, User: root, Password: THE_PASSWORD
    • Works, Adminer shows that I’m logged in as [email protected]
  • Now again use my MySQL client to login.
    • Works! WTF?

Now, what I can figure from this is that the SSH tunnel is likely not the problem as I’m receiving the Access denied for user error message. Previously (when the tunnel was not setup properly) I would get network errors instead of this MySQL error. I also tried adding other users via a MySQL init script. For these users I could reproduce the same problem: Only after one successful login via Adminer, I was able to login via the tunnel.

So maybe Adminer is running some initialization that is currently missing from my setup? Some cache clearing or something?

Configuration files

Here are the configuration files I’m using:

MySQL

Here is my docker-compose.yml for the MySQL server. I also tried to use an init script to bind-address to 0.0.0.0 earlier as well as setting up other users, but that also did not change anything. The network was earlier created via docker network create tunnel

services:
  percona-mysql-server:
    image: percona:8.0
    environment:
      MYSQL_ROOT_PASSWORD: THE_PASSWORD
    expose:
      - "3306"
    volumes:
      - ./percona-data:/var/lib/mysql
    networks:
      - tunnel

  adminer:
    image: adminer
    ports:
      - 8080:8080
    networks:
      - tunnel

networks:
  tunnel:
    external: true

SSH Tunnel

I’ve greatly simplified the tunnel docker-compose.yml for this question and only included the network part as I’m rather sure this is working (as I’m not getting network errors but MySQL errors). Most important, the values AllowAgentForwarding, AllowTcpForwarding, GatewayPorts, X11Forwarding are enabled and I’m connecting via authorized_keys file.

services:
  sshtunnel:
    image: linuxserver/openssh-server:latest
    ...
    ports:
      - 2222:2222
    networks:
      - tunnel

networks:
  tunnel:
    external: true

Why can I only connect via tunnel after once connecting via Adminer?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật