-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcreate-database.dockerfile
More file actions
43 lines (33 loc) · 1.17 KB
/
create-database.dockerfile
File metadata and controls
43 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
FROM mcr.microsoft.com/mssql/server:latest AS build
ENV ACCEPT_EULA=Y \
SA_PASSWORD=P@ssw0rd \
MSSQL_PID=Express
# copy scripts
COPY create-database-scripts/ /sql-scripts/
# switch to root
USER root
# install .net 8.0 sdk
RUN apt-get update && \
apt-get install -y apt-transport-https && \
apt-get update && \
apt-get install -y dotnet-sdk-8.0
# install SqlDatabase.GlobalTool
RUN dotnet tool install --global SqlDatabase.GlobalTool
# create [SqlDatabaseDemo] database from sql-scripts
# 1. start mssql server in the background and wait 20 secs
# 2. create database
# 3. shatdown mssql server
RUN /opt/mssql/bin/sqlservr & \
export PATH="$PATH:/root/.dotnet/tools" && \
SqlDatabase create \
"-database=Data Source=.;Initial Catalog=SqlDatabaseDemo;User Id=sa;Password=P@ssw0rd;ConnectRetryCount=20;ConnectRetryInterval=1" \
-from=/sql-scripts && \
pkill sqlservr
# set mssql user as SqlServer files owner
RUN chown -R mssql /var/opt/mssql/data
FROM mcr.microsoft.com/mssql/server:latest AS runtime
ENV ACCEPT_EULA=Y \
SA_PASSWORD=P@ssw0rd \
MSSQL_PID=Express
# copy mssql server content
COPY --from=build /var/opt/mssql/data/* /var/opt/mssql/data/