The system developed by the outsourcing company, .net framework + sql server, is a big death, and the company requires containerized deployment. Checked a lot of information, no one has done this, the containerization choice is linux, took a lot of detours and finally succeeded under the windows server2019 DataCenter. Make a note of it, and leave it to someone you love.
1. Environment installation
1.1, install SSH:
-Name OpenSSH.Server-WindowsCapability the -ONLINE the Add ~ ~ ~ ~ 0.0 . 1.0 set the server automatically starts the Set -Service sshd - StartupType Automatic the Set -Service SSH-Agent - StartupType Automatic Start - Service sshd Start -Service SSH-Agent
1.2, install docker
DockerMsftProvider -repository-Module -Name the Install PSGallery - Force the Install -package -Name Docker -providerName DockerMsftProvider - Force Docker - v Start Start - Service Docker here to restart it
1.3. Configure the accelerator. If it is not useful, let's configure it. In case it is useful:
C:\ProgramData\docker\config\daemon.json
{ "registry-mirrors": [ "https://cd6xo91e.mirror.aliyuncs.com"] }
1.4, install docker-compose
Invoke-WebRequest https://github.com/docker/compose/releases/download/1.25.4/docker-compose-Windows-x86_64.exe -UseBasicParsing -OutFile $env:ProgramFiles\docker\docker-compose.exe
Second, the custom path database docker
2.1 I tested here, there is no database, I first prepare a database, create a custom path database XD
USE master GO CREATE DATABASE XD ON PRIMARY ( NAME = ' xiding_data ' ,-the main file logical file name FILENAME = ' c: \ sqldb \ xiding_data.mdf ' ,-the main file file name SIZE = 5mb, -the system creates When the main file is allocated, the initial size MAXSIZE = 500MB, -the maximum value of the main file filegrowth = 15 % -the growth rate of the main file ) LOG ON ( name = ' xiding_log ' ,- log file logical file name filename = ' c: \ sqldb \ xiding_log.ldf '- Log file room filename SIZE = 5MB - log file initial size FILEGROWTH = 0 - auto-start growth ) GO
2.2 Create a data table
USE XD create table users ( id int identity(1,1) not null primary key, name nvarchar(50) null, age nvarchar(50) null, ) go
2.3 Just add some data
database and copy the file to the docker host directory when ready, and prepare to mount this directory in docker
Third, after the sqlserver is started in the mirror of mssql, the above database needs to be attached to it
- Statement database references use Master; Go - additional database Create Database XD ON (filename = ' C: \ SQLDB \ xiding_data.mdf ' ), (filename = ' C: \ SQLDB \ xiding_log.ldf ' ) for the attach Go
Fourth, the last docker-compose.yml
version: "3.4" services: weifu_asp: image: mcr.microsoft.com/dotnet/framework/samples:aspnetapp environment: VIRTUAL_HOST: http://admin.shxidsy.com links: - weifu_db ports: - "80:80" volumes: - ./www:c:/inetpub/wwwroot container_name: weifu_asp weifu_db: image: christianacca/mssql-server-windows-express volumes: - ./sql:C:\sqldb environment: ACCEPT_EULA: Y SA_PASSWORD: xdRoot11 attach_dbs: '[{"dbName":"XD","dbFiles":["c:\\sqldb\\xiding_data.mdf","c:\\sqldb\\xiding_log.ldf"]}]' ports: - "9000:1433" container_name: weifu_db
Note: attach_dbs: '[{"dbName": "XD", "dbFiles": ["c: \\ sqldb \\ xiding_data.mdf", "c: \\ sqldb \\ xiding_log.ldf"]}]' The sentence is attached to the database, the directory must use double slashes, killing people
V. Other notes and explanations
1. .net framework (docker) under
windows The docker of the windows host supports .net framework and .net core; the docker of the linux host only supports .net core which
means that the .net framework can only be used under the docker in the windows host, but This is super big: docker pull mcr.microsoft.com/dotnet/framework/samples:dotnetapp
2. The sql server under windows is also called mssql (docker)
. The sql server under windows is super large and cannot be downloaded basically. Microsoft / mssql-server-windows-express, you can use christianacca / mssql-server-windows-express instead of
docker run- e 'ACCEPT_EULA = Y' -e 'SA_PASSWORD = Sa111111' -p 1433: 1433 -vc: \ sqldb: c: \ sqldb --name mssql -d christianacca / mssql-server-windows-express
cannot map the original database folder To the host, otherwise it will always prompt failure, the reason is not specifically investigated, only mapped to other folders, such as c: \ sqldb, and finally attached to the database connection operation.
In docker-compose.yml, map the directory to the host through volumes, and attach the database to the master through attach_dbs.
volumes: - ./sql:C:\sqldb environment: attach_dbs: '[{"dbName":"XD","dbFiles":["c:\\sqldb\\xiding_data.mdf","c:\\sqldb\\xiding_log.ldf"]}]'
Six, test
Refer to another article for a complete test file and process