You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac环境下Docker部署的MySQL容器无法连接Microsoft Azure问题求助

Troubleshooting MySQL Docker Container to Azure Connection Issues on Mac

Hey there, let's work through this connection problem step by step—since you're on a Mac, I'll focus on macOS-specific checks alongside the usual Azure/Docker configurations.

First: Fix the Common Port Misconception

Wait a second—you mentioned using port 1433, but that's the default port for Microsoft SQL Server, not MySQL. MySQL's default port is 3306. This is a super easy mix-up, so let's start here:

  • Verify your Docker container's port mapping: Run docker ps in your terminal and check the "PORTS" column. It should look something like 0.0.0.0:3306->3306/tcp (mapping your Mac's port 3306 to the container's 3306). If you intentionally changed the container's MySQL port to 1433, make sure Azure's firewall is configured to allow that port too.
  • Double-check Azure's MySQL server settings: In the Azure portal, go to your MySQL server's Connection security page and confirm the port matches what your Docker container is using (3306 is standard).

Check Mac's Local Firewall Settings

Mac's built-in firewall might be blocking outbound traffic to Azure. Here's how to adjust it:

  1. Open System Settings > Network > Firewall (you may need to click the lock to make changes).
  2. Click Options to view firewall rules.
  3. Look for Docker Desktop in the list—ensure it's set to Allow incoming connections.
  4. For quick testing, you can temporarily turn off the firewall (don't forget to turn it back on later!) and try connecting again. If it works when the firewall is off, you'll need to add a custom rule to allow traffic to Azure's MySQL server IP/port.

Verify Azure's Network Configuration

Azure's MySQL servers have strict network rules by default—let's confirm your Mac is allowed to connect:

  • IP Allowlist: In the Azure portal, go to your MySQL server's Connection security page. Add your Mac's public IP address to the "Firewall rules" section. You can find your public IP by searching "what's my IP" in a browser.
  • SSL Enforcement: Azure MySQL often requires SSL connections. When you test the connection, make sure you're using the SSL option (e.g., in the MySQL client, add --ssl-mode=REQUIRED). If you're using a GUI tool, look for an SSL checkbox or field to input the SSL certificate (Azure provides this in the portal).
  • Username Format: Azure MySQL usernames need to be in the format admin-username@server-name—don't just use the admin username alone. For example, if your server is named my-mysql-server and your admin is dbadmin, the full username is dbadmin@my-mysql-server.

Test the Connection Directly from Your Mac (Not Docker)

To rule out Docker-specific issues, test connecting to Azure MySQL directly from your Mac's terminal (install MySQL client via Homebrew if you haven't: brew install mysql):

mysql -h your-azure-mysql-server.mysql.database.azure.com -P 3306 -u your-full-username@your-server-name -p --ssl-mode=REQUIRED

If this works, the problem is with your Docker container's network setup. If it fails, the issue is with Azure/Mac firewall settings, not Docker.

Docker Container Network Checks

If the direct Mac connection works but Docker doesn't:

  • Confirm your Docker container has internet access: Run docker exec -it your-mysql-container-name ping google.com to check if the container can reach external networks.
  • Check if you're using a custom Docker network that's isolated. Try restarting the container with the default bridge network, or explicitly allow outbound traffic in your network configuration.
  • Avoid using host network mode on Mac—Docker's host networking works differently on macOS compared to Linux, and it might cause connectivity issues. Stick to the default bridge mode unless you have a specific reason to change it.

内容的提问来源于stack exchange,提问作者new15b

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 13:02:41