This container enables someone to seed a Microsoft SQL database given *.sql seed files.
Every seed file ending in .sql will be picked up in alphabetical order from the main working directory. All you have to do is add them in the base container :)
FROM inforitnl/mssql-seed
COPY ./seed-files .
For the scripts that are ran the following option is enabled by default: sqlcmd -I
.
This sets the SET QUOTED_IDENTIFIER
connection option to ON
. By default, it's set to OFF
. For more information, see SET QUOTED_IDENTIFIER (Transact-SQL).
version: "3.4"
services:
seed:
image: seed-container-name
container_name: seed-container-name
hostname: host.docker.internal
environment:
SQL_DATABASE: "database-to-seed"
extra_hosts:
- host.docker.internal:host-gateway
Variable | Purpose |
---|---|
SQL_CONNECTION_STRING | SQL connection string. When provided it ignores the parameters listed below. |
SQL_HOST | Host to connect to (defaults to 127.0.0.1 ) |
SQL_PORT | Port number to connect to (defaults to 1433 ). |
SQL_USERNAME | username (defaults to sa ) |
SQL_PASSWORD | password (defaults to Your_password123 ) |
SQL_DATABASE | Database name (will be created when not exists) |
-
update dockerfile
-
build local version:
docker build -t inforitnl/mssql-seed .
-
push new version to dockerhub:
docker push inforitnl/mssql-seed
-
tag and push again (optional but recommended):
docker tag inforitnl/mssql-seed inforitnl/mssql-seed:1.0.0 docker push inforitnl/mssql-seed:1.0.0
-
Build test container
docker build -t inforitnl/mssql-seed-test ./test
-
Run
docker-compose up
to start a sql server instance. -
Run the seed test container using:
docker run \ -e SQL_DATABASE="test" \ --network="host" \ inforitnl/mssql-seed-test
As a result both the database (test
) and table (Example
) has been created and the table is filled with 5 example records.