dtc with docker examples

This commit is contained in:
Bob Ward
2018-11-16 17:48:51 -06:00
parent 1460c352a7
commit a1dc1d8953
14 changed files with 140 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
## SQL Server Replication with Containers
This demo uses docker-compose to start two SQL Server containers; one that acts as the publisher and distributor, and the other as the subscriber in a push snapshot configuration.
### How to Use
1. Run the following command in this directory:
```
docker-compose up
```
note: this will take approx. 2 min.
In your terminal, you should see something like this
```
db1 | Job 'DB1-Sales-SnapshotRepl-1' started successfully.
db1 | Creating Snapshot...
db1 | Job 'db1-Sales-SnapshotRepl-DB2-1' started successfully.
```
2. Connect to the subscriber listening on localhost,2600 and see that the Sales Database has a Customer table with data in it.
note: credentials are listed in the **docker-compose.yml**
3. when you are done, clean up by running the following command
```
docker-compose down
```
### How it Works
1. Both SQL Server containers start with the environment variables specified in the docker-compose file. In this example, **db1** is the publisher/distributor and **db2** is the subscriber.
2. *db1/db-init.sh* and *db2/db-init.sh* waits for SQL Server to start up and run the *db-init.sql* scripts
3. *db1/db-init.sql* creates a *Sales* Database with *Customer* table and sample data, and proceeds by setting up snapshot replication.
4. *db2/db-init.sql* creates a *Sales* Database.
5. db1 starts replication jobs to push the snapshot to db2
+32
View File
@@ -0,0 +1,32 @@
version: "3"
services:
dtc1:
build: ./dtc1
environment:
SA_PASSWORD: "Sql2019isfast"
ACCEPT_EULA: "Y"
MSSQL_AGENT_ENABLED: "true"
MSSQL_RPC_PORT: 135
MSSQL_DTC_TCP_PORT: 51999
ports:
- "1401:1433"
- "135:135"
- "51999:51999"
container_name: dtc1
hostname: dtc1
dtc2:
build: ./dtc2
environment:
SA_PASSWORD: "Sql2019isfast"
ACCEPT_EULA: "Y"
MSSQL_AGENT_ENABLED: "true"
MSSQL_RPC_PORT: 135
MSSQL_DTC_TCP_PORT: 51999
ports:
- "1402:1433"
- "136:135"
- "51998:51999"
container_name: dtc2
hostname: dtc2
+1
View File
@@ -0,0 +1 @@
sudo docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=Sql2019isfast' -e 'MSSQL_RPC_PORT=135' -e 'MSSQL_DTC_TCP_PORT=51000' -p 1401:1433 -p 135:135 -p 51000:51000 --hostname dtc1 --network isolated_nw --name dtc1 -d mcr.microsoft.com/mssql/server:vNext-CTP2.0-ubuntu
+1
View File
@@ -0,0 +1 @@
sudo docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=Sql2019isfast' -e 'MSSQL_RPC_PORT=135' -e 'MSSQL_DTC_TCP_PORT=51000' -p 1402:1433 -p 136:135 -p 51001:51000 --hostname dtc2 --network isolated_nw --name dtc2 -d mcr.microsoft.com/mssql/server:vNext-CTP2.0-ubuntu
+6
View File
@@ -0,0 +1,6 @@
FROM mcr.microsoft.com/mssql/server:vNext-CTP2.0-ubuntu
COPY . /
RUN chmod +x /db-init.sh
CMD /bin/bash ./entrypoint.sh
+6
View File
@@ -0,0 +1,6 @@
#wait for the SQL Server to come up
sleep 25s
echo "running set up script"
#run the setup script to create the DB and the schema in the DB
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Sql2019isfast -d master -i db-init.sql
+11
View File
@@ -0,0 +1,11 @@
USE master
GO
EXEC master.dbo.sp_addlinkedserver
@server = N'dtc2', @srvproduct=N'SQL Server'
GO
CREATE DATABASE dtclinux1
GO
USE [dtclinux1]
GO
CREATE TABLE dtctable (col1 int)
GO
@@ -0,0 +1,5 @@
#start SQL Server, start the script to create/setup the DB
#You need a non-terminating process to keep the container alive.
#In a series of commands separated by single ampersands the commands to the left of the right-most ampersand are run in the background.
#So - if you are executing a series of commands simultaneously using single ampersands, the command at the right-most position needs to be non-terminating
/db-init.sh & /opt/mssql/bin/sqlservr
+6
View File
@@ -0,0 +1,6 @@
FROM mcr.microsoft.com/mssql/server:vNext-CTP2.0-ubuntu
COPY . /
RUN chmod +x /db-init.sh
CMD /bin/bash ./entrypoint.sh
+6
View File
@@ -0,0 +1,6 @@
#wait for the SQL Server to come up
sleep 20s
echo "running set up script"
#run the setup script to create the DB and the schema in the DB
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Sql2019isfast -d master -i db-init.sql
+8
View File
@@ -0,0 +1,8 @@
USE master
go
CREATE DATABASE dtclinux2
GO
USE dtclinux2
GO
CREATE TABLE dtctable (col1 int)
GO
@@ -0,0 +1,5 @@
#start SQL Server, start the script to create/setup the DB
#You need a non-terminating process to keep the container alive.
#In a series of commands separated by single ampersands the commands to the left of the right-most ampersand are run in the background.
#So - if you are executing a series of commands simultaneously using single ampersands, the command at the right-most position needs to be non-terminating
/db-init.sh & /opt/mssql/bin/sqlservr
+11
View File
@@ -0,0 +1,11 @@
set xact_abort on
go
begin distributed transaction
go
use dtclinux1
go
insert into dtctable values (1)
insert into dtc2.dtclinux2.dbo.dtctable values (1)
go
commit tran
go
+4
View File
@@ -0,0 +1,4 @@
USE master
GO
EXEC sp_addlinkedserver N'dtc2',N'SQL Server'
GO