Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways to publish SQL Server Docker

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "what are the ways to publish SQL Server Docker". In daily operation, I believe many people have doubts about how to publish SQL Server Docker. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what are the ways to publish SQL Server Docker?" Next, please follow the editor to study!

1 the SQL Server Docker publishing steps for building [database files are built into the container image] are as follows: 1 Pull an original sql server docker image

The image comes from the initial container provided by Microsoft on Docker Hub.

2 write the first version of the database object creation script

SQL script:

CREATE DATABASE CRM GO USE CRM GO CREATE TABLE dbo.Account (AccountId INT IDENTITY (1), AccountName NVARCHAR (200)

Save as DBSchemaInit.sql

3 build a new container image

To build a custom container image, the most important thing is to write Dockerfile.

[root@centos00 v1] # cat DockerfileFROM microsoft/mssql-server-linuxMAINTAINER Lenis Huang "huangyun_122@163.com" ENV ACCEPT_EULA=YENV SA_PASSWORD=1QAZ2WSX3EDCEXPOSE 1433

In the end, the build was successful:

[root@centos00 v1] # docker build-t=sqlserver/v1 .Sending build context to Docker daemon 3.584 kBStep 1 take 5: FROM microsoft/mssql-server-linux-- > b2b20452a15bStep 2 b2b20452a15bStep 5: MAINTAINER Lenis Huang "huangyun_122@163.com"-- > Running in 532a5f141f11-- > 182a1a9aed84Removing intermediate container 532a5f141f11Step 3 Running in 532a5f141f11 5: ENV ACCEPT_EULA Y-- > Running in c72d741f2f8e-- > ee590cf78e2bRemoving intermediate container c72d741f2f8eStep 4 hand 5: ENV SA_PASSWORD 1QAZ2WSX3EDC-> Running in 67559621fd8d-- > 7d92d6155c25Removing intermediate container 67559621fd8dStep 5 seconds ago 5: EXPOSE 1433-> Running in 2bb8ee0440a4-> 67f770bfdacdRemoving intermediate container 2bb8ee0440a4Successfully built 67f770bfdacd [root@centos00 v1] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEsqlserver/v1 latest 67f770bfdacd 36 seconds ago 1.44 GB

At this point, a new sql server docker that can be used for project deployment has been built.

[root@centos00 DockerNginx] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf29258559cb4 sqlserver/v1 "/ opt/mssql/bin/sq..." About a minute ago Up 59 seconds 0.0.0.0 1433/tcp dev_sqlv1 32793->

From the result of the docker ps execution, you can see that the container running the sqlv1 image can be connected to port 1433 corresponding to the sql server service in the container through the local port 32793.

In Dev, STG, and UAT environments, applications are all modeled on sqlv1 to connect to databases running in sqlv1 containers. If there are any problems in the development test, you can rebuild a new container with sqlv1 to run the database.

4 develop a new version of database application and apply it to sqlv1 mirroring Then construct the sqlv2 image # DockerfileFROM sqlserver/v1MAINTAINER Lenis Huang "huangyun_122@163.com" ENV ACCEPT_EULA=YENV SA_PASSWORD=1QAZ2wsx3EDC.ENV PATH=$ {PATH}: / opt/mssql/bin:/opt/mssql-tools/binRUN mkdir sqlfilesCOPY DBSchemaInit.sql. / sqlfiles/DBSchemaInit.sqlCOPY setup-database.sh. / sqlfiles/setup-database.shCOPY entrypoint.sh. / sqlfiles/entrypoint.shRUN chmod astatx. / sqlfiles/setup-database.shRUN chmod astatx. / sqlfiles/entrypoint.shCMD bash. / sqlfiles/entrypoint.sh# entrypoint.shecho 'starting database setup'./sqlfiles/setup-database.sh & / opt/mssql/bin/sqlservr# setup-database.shecho 'please wait while database is starting up...' sleep 45secho 'try to connect to database in containder and create the sample db...'/opt/mssql-tools/bin/sqlcmd-S localhost 1433-U sa-P 1QAZ2wsx3EDC. -d master-I. / sqlfiles/DBSchemaInit.sqlecho 'sample db have been createdholders'

As a database deployment, each time you build a new container, you should focus on writing an incremental deployment script to replace the first database initialization script DBSchemaInit.sql.

5 this cycle to achieve continuous integration and release

In this release process, the question to think about is how to publish in a production environment.

According to the process of docker publishing database, the problems that can be found and avoided are:

Consistency of database publishing scripts.

The same set of scripts are used in dev, stg and uat,prod, and the script can be adjusted in time if there are any errors. Not in a single production environment, because the script logic errors are not checked in time when the dev,stg,uat test environment is released, or because of the influence of the environment, such as people randomly create database objects in the dev,stg,uat environment, the release script itself is not verified for correctness and completeness.

The quickness of database publishing.

Dev,stg,uat,prod was originally required to redeploy a new server. After that, the database publishing script is applied. Now, as long as you make every effort to build a correct and available docker image, based on this image, you can deploy multiple platforms at the same time. The application only needs to specify the corresponding doker name. In a multi-cluster environment, this deployment method brings great convenience to operation and maintenance. Remember Linux's ssh shell, the invention of remote secret login is to allow operators to shuttle between multiple servers, without having to install software one by one. When big data is in charge and requires thousands of cluster servers from time to time, docker can be seen as a good medicine.

What needs to be considered about this process is that the release of the production environment is slightly different. Same release script, but the database file is dissociated from the container. So strictly speaking, the production environment cannot be released in this way. The database file must be isolated from the container from beginning to end. When building the container, first attach the database file to the image, then apply the release script, and finally build the container image of the release version. Such a build script (Dockerfile) is portable. 2 SQL Server Docker publishing steps for building "database files are dissociated from the container image" are as follows:

With the above experience, it is much easier this time, that is, the modification of the Volume instruction is added to Dockerfile. In essence, the disk space in Volume is used to store database files.

The only difference is that dockerfile is written and local files are specified to be mounted.

# Dockerfile FROM sqlserver/v1MAINTAINER Lenis Huang "huangyun_122@163.com" ENV ACCEPT_EULA=YENV SA_PASSWORD=1QAZ2wsx3EDC.ENV PATH=$ {PATH}: / opt/mssql/bin:/opt/mssql-tools/binRUN mkdir sqlfilesCOPY DBSchemaInit.sql. / sqlfiles/DBSchemaInit.sqlCOPY setup-database.sh. / sqlfiles/setup-database.shCOPY entrypoint.sh. / sqlfiles/entrypoint.shRUN chmod astatx. / sqlfiles/setup-database.shRUN chmod astatx. / sqlfiles/entrypoint.shVOLUME / sql/dataCMD bash. / sqlfiles/entrypoint.sh

The VOLUME directive is added to specify that all mounted local files are mounted to / sql/data.

[root@centos00 v4] # mkdir-p / sql/data [root@centos00 v4] # docker run-p 1433-- rm-- name=dev_sqlv5-v sqlvolume:/sql/data sqlserver/v5 [root@centos00 data] # docker volume inspect sqlvolume [{"Driver": "local", "Labels": null, "Mountpoint": "/ var/lib/docker/volumes/sqlvolume/_data", "Name": "sqlvolume" "Options": {}, "Scope": "local"}]

Under the directory specified by sqlvolume, we can see any files that are placed in the / sql/data directory in docker. Of course, we can also create a volume to mount it.

At this point, the study on "what are the ways to publish SQL Server Docker" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report