To establish secure connection of Docker SQL container with XM Cloud Solution you need to create separate network in docker.
A question might occur why we need separate network to establish a connection, when we can use the localhost as a server name and port number with it, Like
“Localhost,14330 “This is how we can define docker server into SSMS portal.
But when we down all the containers, then back them UP, we can see the changed IP Address of the SQL container, where connection breaks and we need to redeploy out connection string with the latest IP Address.
(SQL container connection issue)
We might face an issue shown above, the remote computer refused the network connection
To avoid such kind of errors, we need to use the IP Address and every container restart will change the IP Address of the SQL container.
Now to resolve the same we need to configure static IP to each container present under the XM Cloud docker compose file.
To define the Subnet in the docker environment we need to mention below subnet configuration in the “docker-compose.yml”
networks:
my-network:
ipam:
config:
- subnet: 172.25.0.0/24 # set subnet here
This will create the subnet in the docker environment, further we can now provide static ipv4 IP Address to each container.
We need to mention this in the services section, where all the container configuration will be there,
mssql:
isolation: ${ISOLATION}
image: ${SITECORE_NONPRODUCTION_DOCKER_REGISTRY}nonproduction/mssql-developer:2017-${EXTERNAL_IMAGE_TAG_SUFFIX}
environment:
SA_PASSWORD: ${SQL_SA_PASSWORD}
SITECORE_ADMIN_PASSWORD: ${SITECORE_ADMIN_PASSWORD}
ACCEPT_EULA: "Y"
ports:
- "14330:1433"
networks:
my-network:
ipv4_address: 172.25.0.2 # set static IP
Where my-network will assign the mentioned IP Address to the created container.
Now with the static IP Address we can go ahead with the IP Address as the server’s name of the SQL and connection will not break.
(SSMS connection with IP Address)
To use the same in the visual studio (MCloud Solution) we add the connection string in the Web Config, like below.
(Connection string to connect SQL container with Solution file)
With using this connection with the DB name, User ID and Password the connection will be established with the docker SQL container and XM-Cloud Solution, which gives you full control over the local development with the use of SQL. Like Custom DB and other integrations.
Unlock 40 hour of
free consultation with
our top experts now!