Connect to Sitecore databases running on containers
If you are working on Sitecore development using Docker containers then you would someday definitely need to connect to SQL Server database and query the database tables. Since the SQL Server also running on Docker containers you cannot directly connect to them from SQL Server Management Studio (SSMS). Here are the steps you need to follow to connect to the Databases from SSMS.
1. Fetch container IP address
Get the IP address of the container on which the SQL Server is running on using the following command in Powershell.
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' your_mssql_container_id_here
2. Fetch database credentials
Go to the .env file which is used for the docker setup and fetch the SA password. The variable would be something like this SQL_SA_PASSWORD. Could be different if it is changed on your instance.
3. Connect using SSMS
Connect to the database using the SQL Server Management Studio with
Server name : IP address of the container
Login: sa
Password: Password from .env file
This should connect to the SQL Server and you should see the databases and tables inside them. Hope this helps.