Skip to content

Commit a1dc1d8

Browse files
committed
dtc with docker examples
1 parent 1460c35 commit a1dc1d8

14 files changed

Lines changed: 140 additions & 0 deletions

samples/containers/dtc/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## SQL Server Replication with Containers
2+
3+
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.
4+
5+
6+
### How to Use
7+
8+
1. Run the following command in this directory:
9+
10+
```
11+
docker-compose up
12+
```
13+
note: this will take approx. 2 min.
14+
15+
In your terminal, you should see something like this
16+
```
17+
db1 | Job 'DB1-Sales-SnapshotRepl-1' started successfully.
18+
db1 | Creating Snapshot...
19+
db1 | Job 'db1-Sales-SnapshotRepl-DB2-1' started successfully.
20+
```
21+
22+
2. Connect to the subscriber listening on localhost,2600 and see that the Sales Database has a Customer table with data in it.
23+
note: credentials are listed in the **docker-compose.yml**
24+
25+
3. when you are done, clean up by running the following command
26+
```
27+
docker-compose down
28+
```
29+
30+
31+
32+
### How it Works
33+
34+
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.
35+
2. *db1/db-init.sh* and *db2/db-init.sh* waits for SQL Server to start up and run the *db-init.sql* scripts
36+
3. *db1/db-init.sql* creates a *Sales* Database with *Customer* table and sample data, and proceeds by setting up snapshot replication.
37+
4. *db2/db-init.sql* creates a *Sales* Database.
38+
5. db1 starts replication jobs to push the snapshot to db2
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: "3"
2+
services:
3+
dtc1:
4+
build: ./dtc1
5+
environment:
6+
SA_PASSWORD: "Sql2019isfast"
7+
ACCEPT_EULA: "Y"
8+
MSSQL_AGENT_ENABLED: "true"
9+
MSSQL_RPC_PORT: 135
10+
MSSQL_DTC_TCP_PORT: 51999
11+
ports:
12+
- "1401:1433"
13+
- "135:135"
14+
- "51999:51999"
15+
container_name: dtc1
16+
hostname: dtc1
17+
dtc2:
18+
build: ./dtc2
19+
environment:
20+
SA_PASSWORD: "Sql2019isfast"
21+
ACCEPT_EULA: "Y"
22+
MSSQL_AGENT_ENABLED: "true"
23+
MSSQL_RPC_PORT: 135
24+
MSSQL_DTC_TCP_PORT: 51999
25+
ports:
26+
- "1402:1433"
27+
- "136:135"
28+
- "51998:51999"
29+
container_name: dtc2
30+
hostname: dtc2
31+
32+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM mcr.microsoft.com/mssql/server:vNext-CTP2.0-ubuntu
2+
3+
COPY . /
4+
5+
RUN chmod +x /db-init.sh
6+
CMD /bin/bash ./entrypoint.sh
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#wait for the SQL Server to come up
2+
sleep 25s
3+
4+
echo "running set up script"
5+
#run the setup script to create the DB and the schema in the DB
6+
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Sql2019isfast -d master -i db-init.sql
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
USE master
2+
GO
3+
EXEC master.dbo.sp_addlinkedserver
4+
@server = N'dtc2', @srvproduct=N'SQL Server'
5+
GO
6+
CREATE DATABASE dtclinux1
7+
GO
8+
USE [dtclinux1]
9+
GO
10+
CREATE TABLE dtctable (col1 int)
11+
GO
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#start SQL Server, start the script to create/setup the DB
2+
#You need a non-terminating process to keep the container alive.
3+
#In a series of commands separated by single ampersands the commands to the left of the right-most ampersand are run in the background.
4+
#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
5+
/db-init.sh & /opt/mssql/bin/sqlservr
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM mcr.microsoft.com/mssql/server:vNext-CTP2.0-ubuntu
2+
3+
COPY . /
4+
5+
RUN chmod +x /db-init.sh
6+
CMD /bin/bash ./entrypoint.sh
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#wait for the SQL Server to come up
2+
sleep 20s
3+
4+
echo "running set up script"
5+
#run the setup script to create the DB and the schema in the DB
6+
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Sql2019isfast -d master -i db-init.sql

0 commit comments

Comments
 (0)