3132. Installing Microsoft SQL Server in Docker
SQL Server and Docker

  •  

Create Microsoft SQL Server container in Docker and use Oracle SQL Developer as client tool.

1. What is SQL Server?

SQL Server is a relational database management system (RDBMS) developed by Microsoft. SQL Server is originally released to Windows platform. Recently, Microsoft released the linux version. In this tutorial, we will use docker to install SQL Server for Linux. Thus, we can use it on Mac.

2. Prerequisite

2.1 Docker Machine with Large Storage

The SQL Server container requires at least 3.25 GB of RAM and large storage. If you are unable to install it because of the ‘no space left on device’ error, you have to create a new docker machine with large storage assigned. For more details, refer to Creating Docker Machine with More Disk Space.

3. Creating SQL Server Container in Kitematic

3.1 Creating SQL Server Container

Search mssql-server-linux(Released by Microsoft) in Kitematic, click Create button. image
Kitematic will start to download the image and create container for it. image
The installation takes several minutes. Finally, the container is created but it’s in ‘stopped’ status. We have to make some changes before using it. image

3.2 Environment Variables

Switch to Settings tab, add two environment variables. Accept the license by setting ACCEPT_EULA to Y. And create password for default user sa.

  • ACCEPT_EULA=Y
  • MSSQL_SA_PASSWORD=Abc%123456789

image

3.3 Interactive Shell

Click the ‘EXEC’ button to start an interactive shell. image Now, we are in the bash shell for sql server. image

4. Creating SQL Server Container in Command Line

4.1 Creating SQL Server Container

Download mssql-server-linux image and create container for it.

$ docker pull microsoft/mssql-server-linux
$ docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=Abc%123456789' -p 1401:1433 --name mssql -d microsoft/mssql-server-linux

What is this command doing?

  • Create a mssql-server-linux container named mssql.
  • Set environment variable ACCEPT_EULA to Y.
  • Set environment variable MSSQL_SA_PASSWORD to Abc%123456789.
  • Expose 1433 and map to 1401 for outside world to connect to this SQL Server database.

Check the running containers with following command.

$ docker ps -a

image
In Kitematic, we also see a new container. image
If the container is not launched properly, check logs with following command to get some clues.

$ docker logs <containerid>

4.2 Interactive Shell

Start an interactive bash shell with following command.

docker exec -it mssql "bash"

image

5. Using SQL Server

5.1 Connecting SQL Server

Inside the interactive shell, connect SQL Server locally with sqlcmd.

$ /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Abc%123456789'

5.2 Creating Database

Run the following sql script to create new database named TestDB.

 
 
CREATE DATABASE TestDB
 
SELECT Name from sys.Databases
 
GO

image

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

5.3 Creating Table and Inserting Data

Run the following sql script to create new table named Inventory, and create two rows for it.

 
 
USE TestDB
 
CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)
 
INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);
 
GO

image

5.4 Querying Data

Run the following sql script to find rows whose quantity is larger than 152.

 
 
SELECT * FROM Inventory WHERE quantity > 152;
 
GO

image

6. SQL Client Tool

It’s more convenient to use UI client tool to manipulate database.

6.1 Getting Oracle SQL Developer

Go to http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html, download SQL Developer for Mac OSX. Unzip the package file, there is only one file named SQLDeveloper.

6.2 Getting Plugin File

Go to https://sourceforge.net/projects/jtds/files/, downland jtds-1.3.1-dist.zip. Extract jtds-1.3.1.jar from the package file. It is a plugin module for SQL Server and Sybase JDBC.

6.3 Importing Plugin to SQL Developer

Launch SQL Developer, go to -> Preferences -> Database -> Third-party JDBC Drivers, add the jar file. image

6.4 Creating Connection

In SQL Developer, New Connection.., provide the user, password, host and port mentioned when we create the SQL Server container. Test and Connect. image
Connection is created. After expanding the nodes by level, you will see the database and table we created through bash shell. image

6.5 Running Query

Right-click on the TestDB database, and choose Select Default Database. image
Then, apply. image
In the worksheet, input the following sql script and run. You will see all rows in table Inventory.

SELECT * FROM Inventory;

image

7. Others

7.1 Restoring Database with Backup File

The following command copies the backup file named ShoeStore.bak to the root directory of SQLServer container named mssql.

$ docker cp ShoeStore.bak mssql:/ShoeStore.bak

Go to interactive bash shell and connect to SQL Server.

$ docker exec -it mssql "bash"
$ /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Abc%123456789'

Use the following sql script to restore the database.

RESTORE DATABASE ShoeStore
FROM DISK = '/ShoeStore.bak'
WITH MOVE 'ShoeStore' TO '/var/opt/mssql/data/ShoeStore.mdf',
MOVE 'ShoeStore_Log' TO '/var/opt/mssql/data/ShoeStore_Log.ldf'
GO

For .Net Applications, the connectionString looks like below. 1401 is the port number.

<add name="EFDbContext" connectionString="server=192.168.99.100,1401;database=ShoeStore;uid=sa;pwd=Abc%123456789;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient" />

8. References

[source] https://jojozhuang.github.io/tutorial/docker/installing-microsoft-sql-server-in-docker/

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
공지 오라클 기본 샘플 데이터베이스 졸리운_곰 2014.01.02 86174
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78661
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95397
664 char-lstm-rnn-keras, Kinetic korean 한글 file 졸리운_곰 2020.01.28 1518
663 min-char-rnn 한글 주해(3) - 손실값 계산, 그래디언트 계산, 문자 출력함수 file 졸리운_곰 2020.01.28 917
662 min-char-rnn 한글 주해(2) - 메인 루프 file 졸리운_곰 2020.01.28 1179
661 min-char-rnn 한글 주해(1) - 데이터 준비, 변수 초기화 file 졸리운_곰 2020.01.28 1256
660 RNN(Recurrent Neural Network)과 Torch로 발라드곡 작사하기 file 졸리운_곰 2020.01.28 1128
659 파이토치(pyTorch)란 무엇일까? 졸리운_곰 2020.01.28 969
658 딥러닝 구현 라이브러리, 파이토치(Pytorch) file 졸리운_곰 2020.01.28 1047
657 [ms sql server] T-SQL 저장 프로시져 만들기 : CREATE PROCEDURE(Transact-SQL) file 졸리운_곰 2020.01.27 1925
656 [ms sql server] 저장 프로시저 만들기 file 졸리운_곰 2020.01.27 1102
» Installing Microsoft SQL Server in Docker SQL Server and Docker file 졸리운_곰 2020.01.26 9140
654 MS SQL Stored Procedure file 졸리운_곰 2020.01.26 1687
653 [MSSQL] 저장 프로시저 만들기 실습 file 졸리운_곰 2020.01.26 1667
652 lightGBM 설치 및 예제 (How to install Lightgbm and example) 졸리운_곰 2020.01.26 872
651 MS-SQL 에서 한글 검색이 안되는 경우 졸리운_곰 2020.01.24 1423
650 MySQL 세자리 마다 콤마 찍기 file 졸리운_곰 2020.01.24 1018
649 mssql 2012 언어변경 질문드립니다. file 졸리운_곰 2020.01.23 1501
648 [MS-SQL] 쿼리문 정리 file 졸리운_곰 2020.01.23 1940
647 [DB/Docker/MSSQL] Docker + MSSQL 개발하기 졸리운_곰 2020.01.23 1368
646 Linux에서 환경 변수를 사용하여 SQL Server 설정 구성 file 졸리운_곰 2020.01.23 1241
645 docker mysql 한글 깨짐 해결 & 초기 설정 졸리운_곰 2020.01.23 1977
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED