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

How to install SQL Server database in Linux system through Docker

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to install SQL Server database in Linux system through Docker". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to install SQL Server database in Linux system through Docker".

I. Preface

Now the .NET Core is cross-platform, supporting Windows, Linux, and Mac systems, and we have also used Docker on Linux. The most frequently used by developers using .NET is SQL Server data, which used to be available only on Windows systems, but it has been supported on docker since SQL Server 2017, which means that SQL Server can now run on Linux.

The database used in this article is SQL Server 2017.

2. Install SQL Server1 and pull SQL Server image

To install SQL Server in Docker, you must first have an image of SQL Server, so the first step is to pull the SQL Server image

Sudo docker pull mcr.microsoft.com/mssql/server:2017-latest

As shown in the figure

2. Create a directory

We know that once the Docker container is deleted, the data in the container will be lost, so we create a directory on the host to mount the directory in the container.

Mkdir / etc/sqlserver_data

As shown in the figure

3. Run the container

Once we have the image, we can run the container according to the image.

Sudo docker run-e "ACCEPT_EULA=Y"-e "SA_PASSWORD=P@ssw0rd,"-p 1433 SA_PASSWORD=P@ssw0rd 1433-- name sqlserver2017-v / etc/sqlserver_data:/var/opt/mssql-d mcr.microsoft.com/mssql/server:2017-latest

We explain the above command as follows

-e "SA_PASSWORD=P@ssw0rd,": here is the login password set for the SA user, and the password set here is P@ssw0rd.

-v / etc/sqlserver_data:/var/opt/mssql: indicates that the / etc/sqlserver_data directory is mounted to the container's / var/opt/mssql directory. This directory is used to store database files, so it is best to mount it outside the container to avoid data loss due to accidental deletion of the container.

-p 1433: indicates that port 1433 of the host is mapped to 1433 of the container.

As shown in the figure

4. Use the command to enter SQL Server

After the container is running, we use the exec command to enter the SQL Server

Docker exec-it sqlserver2017 / bin/bash

As shown in the figure

So we go inside the container and execute the following command:

/ opt/mssql-tools/bin/sqlcmd-S localhost-U SA-P ""

The command in the example is as follows:

/ opt/mssql-tools/bin/sqlcmd-S localhost-U SA-P P@ssw0rd

If successful, the sqlcmd command prompt: 1 > should be displayed.

As shown in the figure

Execute the following command to query the data

Select name from sys.Databases

As shown in the figure

You can query the results.

We create the database by command, then create the table and insert some data.

5. Log in to SQL Server database using SSMS

Above, we directly use commands to operate the database. We can also use Microsoft SQL Server Management Studio (SSMS) to log in to the database in Docker, and then operate the database through a graphical interface.

Use SSMS to connect to SQL Server on Linux and refer to Microsoft's official documentation: https://docs.microsoft.com/zh-cn/sql/linux/sql-server-linux-manage-ssms?view=sql-server-2017

After logging in successfully, we query the data, as shown in the figure

We insert a piece of data into the student table

Let's check in Docker to see if the data has changed.

We see that the data in docker has also changed. Using SSMS to manipulate a database is the same as using commands in docker to manipulate the database directly.

At this point, I believe that everyone on the "Linux system through Docker how to install SQL Server database" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Development

Wechat

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

12
Report