An Azure service that provides a general-purpose, serverless container platform.
Add an internal DNS suffix to the Container App Environment and use a private DNS zone for the MySQL Flexible Server. You'll need to configure the Container App to use the private DNS zone for name resolution.
- Container App Environment (CAE)
Modify the Container App Environment to be VNet-integrated. This allows the backend to resolve private endpoints within the virtual network. However, since the front end needs to remain public, you should keep the ingress as public. The key change is to ensure that the CAE is configured to properly use the VNet's DNS settings.
- Private DNS Zone
Link the Private DNS Zone for your MySQL Flexible Server to the virtual network where your Container App is deployed. This is crucial for name resolution. The CAE will then be able to resolve the private endpoint of the MySQL server. The DNS zone should have an A record that maps the MySQL server's hostname to its private IP address.
- Frontend and Backend
To allow the backend to connect privately while keeping the frontend public, ensure the backend container app is configured to use the VNet-integrated CAE. The frontend container app can remain in the same environment and use public ingress. The VNet integration applies to the entire CAE, but you can control public access for individual apps.
- Environment Flags
You may need to explicitly configure the container app to use the private DNS zone. In some cases, the container's /etc/resolv.conf may not automatically pick up the VNet's DNS settings. You can try to set an environment variable or a startup command within the container to point to the correct DNS server, which would be the VNet's DNS resolver IP.
For the backend: The connection string should use the fully qualified domain name (FQDN) of the MySQL server, not its private IP directly. The private DNS zone will handle the resolution to the private IP.
For the frontend: No changes are required.
Summary of Fix
Verify that the Azure DNS Private Zone for MySQL is linked to the spoke VNet. If it isn't, link it.
Ensure that your Container App is deployed in a VNet-integrated Container App Environment.
Ensure the connection string in the backend app is using the fully qualified domain name (FQDN) of the MySQL server and not its private IP address.
If the issue persists, check the networking settings of the CAE to confirm it's using the VNet's DNS, or manually configure the container's DNS settings.