diff --git a/docker-compose.yml b/docker-compose.yml index 8a21767f..cde5c83e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -176,6 +176,22 @@ services: networks: - backend +### MsSQL Container ######################################### + + mssql: + build: + context: ./mssql + environment: + - MSSQL_DATABASE=${MSSQL_DATABASE} + - SA_PASSWORD=${MSSQL_PASSWORD} + - ACCEPT_EULA=Y + volumes: + - mssql:/var/opt/mssql + ports: + - "${MSSQL_PORT}:1433" + networks: + - backend + ### MariaDB Container ####################################### mariadb: diff --git a/mssql/Dockerfile b/mssql/Dockerfile new file mode 100644 index 00000000..fd9f0761 --- /dev/null +++ b/mssql/Dockerfile @@ -0,0 +1,21 @@ +FROM microsoft/mssql-server-linux + +# Create config directory +# an set it as WORKDIR +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +# Bundle app source +COPY . /usr/src/app + +RUN chmod +x /usr/src/app/create_table.sh + +ENV MSSQL_DATABASE=$MSSQL_DATABASE +ENV ACCEPT_EULA=Y +ENV SA_PASSWORD=$MSSQL_PASSWORD + +VOLUME /var/opt/mssql + +EXPOSE 1433 + +CMD /bin/bash ./entrypoint.sh \ No newline at end of file diff --git a/mssql/create_table.sh b/mssql/create_table.sh new file mode 100644 index 00000000..f0c1a7c6 --- /dev/null +++ b/mssql/create_table.sh @@ -0,0 +1,5 @@ +#wait for the SQL Server to come up +sleep 45s + +#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 \ No newline at end of file diff --git a/mssql/entrypoint.sh b/mssql/entrypoint.sh new file mode 100644 index 00000000..e3835130 --- /dev/null +++ b/mssql/entrypoint.sh @@ -0,0 +1,2 @@ +#start SQL Server, start the script to create the DB and import the data, start the app +/opt/mssql/bin/sqlservr.sh & /usr/src/app/create_table.sh & tail -f /dev/null \ No newline at end of file diff --git a/mssql/setup.sql b/mssql/setup.sql new file mode 100644 index 00000000..f453c778 --- /dev/null +++ b/mssql/setup.sql @@ -0,0 +1,4 @@ +CREATE DATABASE $(MSSQL_DATABASE); +GO +USE $(MSSQL_DATABASE); +GO \ No newline at end of file