How to run my script inside kubernetes yaml deployment file

Hi Everyone,

I create a new image base on the “” image.
Then I have a script to create a new database with some tables with seeded data within the Dockerfile.

USER root

# CreateDb
COPY ./CreateDatabaseSchema.sql ./opt/scripts/


# 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.

      - name: processingdb
        image: jdang67/mssqlserver-invariant:latest
        - containerPort: 1433
        - name: MSSQL_PID
          value: "Express"
        - name: ACCEPT_EULA
          value: "Y"
        - name: SA_PASSWORD
          value: myPassword@&1
          - 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.
"sleep 30; /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ${SA_PASSWORD} -d master -i /opt/scripts/myScript.sql"


John Dang

The [] indicates a list, so in order to make it valid syntax you would need to split your string line into single strings seperated by , character. Though, what you try is not the indendet approach.

The dockerhub description points out what to do:

You can also use the tools in an script to do things like create databases or logins, attach databases, import data, or other setup tasks. See this example of using an script to create a database and schema and bcp in some data.

Inspect the repo from above, check what they do in the Dockerfile to call the entrypoint script, check the entrypoint script itself and than the script it calls.

I just want to learn how to run scripts from the deployment file. Your example is running the script from dockerfile.


The way you declared it will not work.
command: [] will set the entrypoint script to nothing, thus the whole bootraping process needs to be done in args: [] (which is the command in docker). You will need to put whatever is required to start the server, put it in the background and run your own command in there. Like i wrote before, you will need to split your string into single strings, e.g. instead of the format ["a b c"] it has to follow the format ["a","b","c"].

The “I want to use a command” makes more sense if e.g. if a configMap injects the file into the container filesystem. You already modify the image, what good is it to frankenstein your container, if the image maintainer itself suggest a clean approach?

Never the less: hope you will find what you are loocking for!