Skip to content

Commit 04db4e0

Browse files
committed
Add support for ms sql server in docker-compose
1 parent d69ec08 commit 04db4e0

File tree

6 files changed

+68
-16
lines changed

6 files changed

+68
-16
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Set COMPOSE_PROFILES to one of the following: postgres, mysql, mssql
2+
COMPOSE_PROFILES=mssql

docker-compose.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1+
# You can easily switch between different databases by changing the value of COMPOSE_PROFILES in the .env file.
12
services:
2-
test:
3-
image: debian:stable-slim
4-
volumes:
5-
- .:/var/www
6-
depends_on:
7-
- db
8-
environment:
9-
DATABASE_URL: ${DB:-postgres}://root:secret@db/sqlpage
103
web:
114
build: { context: "." }
125
ports:
136
- "8080:8080"
147
volumes:
158
- .:/var/www
169
depends_on:
17-
- db
10+
- ${COMPOSE_PROFILES-postgres}
1811
environment:
19-
DATABASE_URL: ${DB:-postgres}://root:secret@db/sqlpage
20-
db: # The DB environment variable can be set to "mariadb" or "postgres" to test the code with different databases
21-
ports:
22-
- "5432:5432"
23-
- "3306:3306"
24-
image: ${DB:-postgres}
12+
DATABASE_URL: ${COMPOSE_PROFILES-postgres}://root:secret@${COMPOSE_PROFILES:-postgres}/sqlpage
13+
postgres:
14+
profiles: ["postgres"]
15+
ports: ["5432:5432"]
16+
image: postgres
2517
environment:
2618
POSTGRES_USER: root
2719
POSTGRES_DB: sqlpage
2820
POSTGRES_PASSWORD: secret
21+
mysql:
22+
profiles: ["mysql"]
23+
ports: ["3306:3306"]
24+
image: mysql
25+
environment:
2926
MYSQL_ROOT_PASSWORD: secret
30-
MYSQL_DATABASE: sqlpage
27+
MYSQL_DATABASE: sqlpage
28+
mssql:
29+
profiles: ["mssql"]
30+
ports: ["1433:1433"]
31+
build: { context: "mssql" }

mssql/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
ARG VERSION=2019-latest
2+
FROM mcr.microsoft.com/mssql/server:${VERSION}
3+
4+
# Create a config directory
5+
RUN mkdir -p /usr/config
6+
WORKDIR /usr/config
7+
8+
# Bundle config source
9+
COPY entrypoint.sh /usr/config/entrypoint.sh
10+
COPY configure-db.sh /usr/config/configure-db.sh
11+
COPY setup.sql /usr/config/setup.sql
12+
13+
# Grant permissions for to our scripts to be executable
14+
USER root
15+
RUN chmod +x /usr/config/entrypoint.sh
16+
RUN chmod +x /usr/config/configure-db.sh
17+
RUN chown 10001 /usr/config/entrypoint.sh
18+
RUN chown 10001 /usr/config/configure-db.sh
19+
USER 10001
20+
21+
ENV SA_PASSWORD="Password123!"
22+
ENV ACCEPT_EULA="Y"
23+
24+
ENTRYPOINT ["/usr/config/entrypoint.sh"]

mssql/configure-db.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
# Wait 15 seconds for SQL Server to start up
4+
sleep 15
5+
6+
# Run the setup script to create the DB and the schema in the DB
7+
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -d master -i setup.sql

mssql/entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
# Start the script to create the DB and user
4+
/usr/config/configure-db.sh &
5+
6+
# Start SQL Server
7+
/opt/mssql/bin/sqlservr

mssql/setup.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
IF DB_ID('sqlpage') IS NULL
2+
BEGIN
3+
CREATE DATABASE sqlpage;
4+
END;
5+
GO
6+
7+
USE sqlpage;
8+
GO
9+
10+
CREATE USER root WITH PASSWORD = 'secret';
11+
GO

0 commit comments

Comments
 (0)