I. Introduction
.NET Core now has a cross-platform, supports Windows, Linux, Mac systems, and we have used in the Linux Docker above. Use .NET development people use most is the SQL Server data, previously only available on Windows systems, but running, which means that SQL Server can now run from the SQL Server 2017 began to support on the docker on Linux.
This article will explain how to use the docker to install SQL Server. Used here is Contos7, other versions of the Linux operating system, too. Database using SQL Server 2017.
Second, install SQL Server
1, pull SQL Server mirroring
To install SQL Server in Docker, first there must be mirrored SQL Server, so the first step is to pull SQL Server mirroring
sudo docker pull mcr.microsoft.com/mssql/server:2017-latest
as the picture shows
2, create a directory
We know, Docker container once removed, the data will be lost inside the container, so we create a directory on the host upon which to mount the directory within the container.
mkdir /etc/sqlserver_data
as the picture shows
3, run container
With the mirror after that we can go run a container according to the mirror.
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=P@ssw0rd," -p 1433:1433 --name sqlserver2017 -v /etc/sqlserver_data:/var/opt/mssql -d mcr.microsoft.com/mssql/server:2017-latest
We make the following explanation of the above command
-
-e "SA_PASSWORD = P @ ssw0rd,": here is to set the SA user login password, the password set here is the P @ ssw0rd ,.
-
-v / etc / sqlserver_data: / var / opt / mssql: indicates / etc / sqlserver_data directory is mounted to the container / var / opt / mssql directory, which is used to store the database file, so it is best to mount the container outside, avoid the container accidentally deleted data loss.
-
-p 1433: 1433: 1433 represents the mapping of the host port to the container 1433.
as the picture shows
4, use the command to enter the SQL Server
After the container operation, we use the exec command to enter the internal SQL Server
docker exec -it sqlserver2017 /bin/bash
as the picture shows
In this way we enter the interior of the container, and then execute the following command:
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "<YourNewStrong@Passw0rd>"
In an example, the following command:
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P P@ssw0rd,
If successful, it should show sqlcmd command prompt: 1>
.
as the picture shows
Execute the following command, query data
select name from sys.Databases
as the picture shows
You can check out the results.
We create the database by way of command, and then create a table and insert some data.
5, use SSMS to log SQL Server database
We are the direct use of the above commands manipulate a database, we can also use Microsoft SQL Server Management Studio (SSMS) to log Docker inside the database, and then through the graphical interface of the operation of the database
Use SSMS connected on Linux Reference Microsoft SQL Server official documentation: https://docs.microsoft.com/zh-cn/sql/linux/sql-server-linux-manage-ssms?view=sql-server-2017
After successful login we query the data, as shown in Figure
We insert data into a table inside the student
Docker we look at it, look at the data has not changed
We see docker inside the data has changed. Use SSMS to operate the database just like using the command in the same database operations directly inside docker.
Third, the summary
The above brief introduction about how to install the SQL Server database by Docker on a Linux system, installed after, we can use SSMS operation Docker inside the database, just like the installation of Windows on top of SQL Server operating same. More documents can refer to Microsoft's official website: