If you want to see MS SQL Server database composed up with Dotnet Core app, I have created demo for it as well (even if you are not interested in. Luckily workaround is already prepared, and I hope thatĪfter reading this article it’s easy to understand how exactly it works. Unfortunately Microsoft didn’t get this done so far, so at this moment we need to use ugly hack with sleep. Initializing DB server could be equally simple like in MySQL, but Starting new Docker container with Microsoft SQL Server is really simple. That way or another, upgrade MSSMS to the newest version, because as far as I know MSSMS caches internal DB name and doesn’t refresh it, so there is mismatch. Moreover, at the moment of writing this article, Microsoft SQL Server Management Studio must be restarted every time container is stopped and recreated from scratch, because Like I have written before, always remember to set Unix EOL in files which you copy to Docker image, otherwise you may have incomprehensible bugs. Troubleshooting MS SQL Docker initialization I feel that it’s cleaner this way but don’t have any tangible evidence that it’s better. I prefer do it this way to separate schema from data, but it’s just my preference, To do so first generate script with Schema only, then once again with Data only. opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P yourStrong (!)Password -d master -i fill-database.sql opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P yourStrong (!)Password -d master -i create-database.sql You can also separate scripts to create schema (empty database) and to add data (fill database), and just run sqlcmd utility several times: You can choose in advanced options Types of data to scripts - Schema and data. You can script whole database with data included, straight from Microsoft SQL Server Management studio, just click on database name, choose Tasks -> Generate Scripts… and It’s good solution, because you will probably use volume that way or another, to easily persist database. You can have your database files already on disk and new server instance just mounted to it with Docker volume. Just save database state, then you can recreate whole environment with bug already prepared, as many times as you need.īut this way is not recommended for production, because you don’t see explicitly what is in this data so it’s hard to maintain. It can be useful for example when you reproduced bug and don’t want to lose it during debugging. If it’s only for debugging purposes you can do Docker commit to save container state as new image, to recreate it whenever you want. If you need to have database filled with data, there are several ways to achieve that. That’s it, whole Dockerfile is available in mentioned GitHub repo. RUN chmod +x /usr/src/app/run-initialization.sh It’s not my idea, this is solution currently recommended by Microsoft and nothing better comes to my mind neither.įirst we override Dockerfile CMD entry from base image (which runs SQL server), with our own CMD command, which runs our custom script: The hack is to run at the same time SQL Server and script which will sleep 90seconds (to be sure that server already started) then do whole initialization (we’ll see how). Now it’s time to add extra stuff to have initialization in our server. How to initialize MS SQL server in Docker container So for example let’s choose version: FROM /mssql/server:2017-CU17-ubuntu (all tags list is usually given in Docker Hub image description). We should also use explicit image version (not latest) to be sure that this Dockerfile will always be valid (new versions will not break down Docker build or runtime initialization in container). We can additionally add EXPOSE 1433 entry to Dockerfile, to be able to access it from composed containers.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |