Add support for ms sql server in docker-compose

This commit is contained in:
lovasoa
2023-07-30 11:49:41 +02:00
parent 6bb78b53a7
commit e01bfa066d
6 changed files with 68 additions and 16 deletions
+2
View File
@@ -0,0 +1,2 @@
# Set COMPOSE_PROFILES to one of the following: postgres, mysql, mssql
COMPOSE_PROFILES=mssql
+17 -16
View File
@@ -1,12 +1,5 @@
# You can easily switch between different databases by changing the value of COMPOSE_PROFILES in the .env file.
services:
test:
image: debian:stable-slim
volumes:
- .:/var/www
depends_on:
- db
environment:
DATABASE_URL: ${DB:-postgres}://root:secret@db/sqlpage
web:
build: { context: "." }
ports:
@@ -14,17 +7,25 @@ services:
volumes:
- .:/var/www
depends_on:
- db
- ${COMPOSE_PROFILES-postgres}
environment:
DATABASE_URL: ${DB:-postgres}://root:secret@db/sqlpage
db: # The DB environment variable can be set to "mariadb" or "postgres" to test the code with different databases
ports:
- "5432:5432"
- "3306:3306"
image: ${DB:-postgres}
DATABASE_URL: ${COMPOSE_PROFILES-postgres}://root:secret@${COMPOSE_PROFILES:-postgres}/sqlpage
postgres:
profiles: ["postgres"]
ports: ["5432:5432"]
image: postgres
environment:
POSTGRES_USER: root
POSTGRES_DB: sqlpage
POSTGRES_PASSWORD: secret
mysql:
profiles: ["mysql"]
ports: ["3306:3306"]
image: mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: sqlpage
MYSQL_DATABASE: sqlpage
mssql:
profiles: ["mssql"]
ports: ["1433:1433"]
build: { context: "mssql" }
+24
View File
@@ -0,0 +1,24 @@
ARG VERSION=2019-latest
FROM mcr.microsoft.com/mssql/server:${VERSION}
# Create a config directory
RUN mkdir -p /usr/config
WORKDIR /usr/config
# Bundle config source
COPY entrypoint.sh /usr/config/entrypoint.sh
COPY configure-db.sh /usr/config/configure-db.sh
COPY setup.sql /usr/config/setup.sql
# Grant permissions for to our scripts to be executable
USER root
RUN chmod +x /usr/config/entrypoint.sh
RUN chmod +x /usr/config/configure-db.sh
RUN chown 10001 /usr/config/entrypoint.sh
RUN chown 10001 /usr/config/configure-db.sh
USER 10001
ENV SA_PASSWORD="Password123!"
ENV ACCEPT_EULA="Y"
ENTRYPOINT ["/usr/config/entrypoint.sh"]
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Wait 15 seconds for SQL Server to start up
sleep 15
# Run the setup script to create the DB and the schema in the DB
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -d master -i setup.sql
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Start the script to create the DB and user
/usr/config/configure-db.sh &
# Start SQL Server
/opt/mssql/bin/sqlservr
+11
View File
@@ -0,0 +1,11 @@
IF DB_ID('sqlpage') IS NULL
BEGIN
CREATE DATABASE sqlpage;
END;
GO
USE sqlpage;
GO
CREATE USER root WITH PASSWORD = 'secret';
GO