Skip to content

Connect to SQL Server from Docker container

Connect to Local MS SQL Server from Docker container

  • The docker container is running as a separate machine inside your host machine. Hence the Data Source=(local) or named server is not the same when the app runs inside the docker.

  • So, we need to access the SQL Server over the network then only the docker can connect to it.

  • Make sure the TCP/IP protocol is enabled over the network for SQL Server in the Configuration Manager and the remote connections are also allowed to your SQL server.

img

Make sure the_IP Address_is 1433

img

  • We use connection string to connect to your SQL Server. Here is an example.

Data Source=host.docker.internal;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;TrustServerCertificate=True;

  • Copy the connection string and make changes on the myDatabase, myUsername and myPassword parts according to your SQL server

  • If you want to create a new database in SQL server to connect to docker container, check on How to prepare database in SQL Server and connect to docker container

  • Login to System Admin and go to Database screen in the docker container application. Click on the Edit button in the window

img

  • Change the Server Type into Cloud and paste the connection string on the following field.

img

  • Save the changes and and Upgrade the database. Click on the Test Connection button and you'll get a success message.

  • Now you're connected to the local SQL server database in docker container application.