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 86310
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78764
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95511
78 [Kafka] Kafka 한번 살펴보자... Quickstart file 졸리운_곰 2021.06.18 1309
77 Java Kafka Producer, Consumer 예제 구현 Java를 이용하여 Kafka Producer와 Kakfa Consumer를 구현해보자. file 졸리운_곰 2021.06.18 1170
76 Beginner’s Guide to Understand Kafka file 졸리운_곰 2021.06.18 1572
75 [Kafka] Kafka 설치/실행 및 테스트 file 졸리운_곰 2021.06.18 1065
74 [java] [kafka] [Kafka] 개념 및 기본예제 file 졸리운_곰 2021.06.16 2170
73 Getting started with Apache Kafka in Python file 졸리운_곰 2020.09.10 2256
72 [Kafka] 다운로드 및 Quick Start file 졸리운_곰 2020.09.07 1893
71 [Kafka] 기본 개념잡기 file 졸리운_곰 2020.09.07 1705
70 Flume Integration with Kafka file 졸리운_곰 2019.04.16 2081
69 빅데이터: 플럼(Flume) 토폴로지 설계 file 졸리운_곰 2019.04.16 1600
68 실시간 처리를 위한 분산 메시징 시스템 카프카(Kafka) file 졸리운_곰 2018.05.12 1410
67 Flume과 Kafka를 사용한 초당 100만개 로그 수집 테스트 file 졸리운_곰 2018.05.12 1378
66 웹 크롤링 / web crwaling / web scraping / 웹 스크래핑 file 졸리운_곰 2017.07.09 1848
65 빅데이터 단지 몇퍼센트의 예측 정확성을 위하여 장애로 가득찬 빅데이터 시스템을 도입하여야 하는가에 대한 의문! file 졸리운_곰 2017.03.20 1605
64 빅데이터: 플럼(Flume) 토폴로지 설계 file 졸리운_곰 2017.03.20 1416
63 [실시간 분석 시스템] Apache Flume를 활용한 데이터 수집(1) file 졸리운_곰 2017.03.06 1316
62 [실시간 분석 시스템] 데이터 수집 #2 Apache Sqoop을 활용하여 RDBMS 데이터 수집(2) file 졸리운_곰 2017.03.06 1385
61 [실시간 분석 시스템] 데이터 수집 #2 Apache Sqoop을 활용하여 RDBMS 데이터 수집(1) file 졸리운_곰 2017.03.06 1104
60 [실시간 분석 시스템] 데이터 수집 #1 오픈 소스 수집기 비교 file 졸리운_곰 2017.03.06 1746
59 [실시간 분석 시스템] 일단 데이터 들여다 보기 file 졸리운_곰 2017.03.06 1935
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED