Hi Everyone,
I create a new image base on the “mcr.microsoft.com/mssql/server” image.
Then I have a script to create a new database with some tables with seeded data within the Dockerfile.
FROM mcr.microsoft.com/mssql/server
USER root
# CreateDb
COPY ./CreateDatabaseSchema.sql ./opt/scripts/
ENV ACCEPT_EULA=true
ENV MSSQL_SA_PASSWORD=myP@ssword#1
# Create database
RUN /opt/mssql/bin/sqlservr & sleep 60; /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ${MSSQL_SA_PASSWORD} -d master -i /opt/scripts/CreateDatabaseSchema.sql
If I attach to a persistent volume, then then the databases that I created in the dockerfile are gone.
Since I already have scripts inside my images, I want to run those scripts after volumneMounting but I don’t know the syntax.
spec:
containers:
- name: processingdb
image: jdang67/mssqlserver-invariant:latest
ports:
- containerPort: 1433
env:
- name: MSSQL_PID
value: "Express"
- name: ACCEPT_EULA
value: "Y"
- name: SA_PASSWORD
value: myPassword@&1
volumeMounts:
- mountPath: /var/opt/mssql
name: mssqldb-wp
command: []
args: ["/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P myPassword@&1 -d master -i /opt/scripts/CreateDatabaseSchema..sql"]
#restartPolicy: Never
Ideally, I want to sleep 30s then calling the script but I could find any example yet.
EX:
"sleep 30; /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ${SA_PASSWORD} -d master -i /opt/scripts/myScript.sql"
thanks,
John Dang