Running Microsoft SQL Server in Docker on Ubuntu
This guide shows how to run Microsoft SQL Server in Docker and connect to it using either the command line (sqlcmd) or IntelliJ IDEA's…
Running Microsoft SQL Server in Docker on Ubuntu

This guide shows how to run Microsoft SQL Server in Docker and connect to it using either the command line (sqlcmd) or IntelliJ IDEA's Database tool (DataGrip).
Step 1: Pull the SQL Server image
docker pull mcr.microsoft.com/mssql/server:2022-latest
Step 2: Create and start the container
docker run -d \
--name sqlserver \
-e "ACCEPT_EULA=Y" \
-e "MSSQL_SA_PASSWORD=StrongPassword123!" \
-p 1433:1433 \
mcr.microsoft.com/mssql/server:2022-latest
Verify that the container is running:
docker ps
Connect using the command line
Open a terminal and execute:
docker exec -it sqlserver /opt/mssql-tools18/bin/sqlcmd \
-S localhost \
-U sa \
-P 'StrongPassword123!' \
-C
If your image uses the older tools path:
docker exec -it sqlserver /opt/mssql-tools/bin/sqlcmd \
-S localhost \
-U sa \
-P 'StrongPassword123!'
You should see:
1>
Create a new database:
CREATE DATABASE [sqlserver-demo];
GO
Switch to it:
USE [sqlserver-demo];
GO
Verify the current database:
SELECT DB_NAME();
GO
Exit:
QUIT
Connect using IntelliJ IDEA (Database / DataGrip)
- Open View → Tool Windows → Database.
- Click + → Data Source → Microsoft SQL Server.
- Enter the following details:
Host: localhost
Port: 1433
Database: master
Username: sa
Password: StrongPassword123!
Alternatively, use this JDBC URL:
jdbc:sqlserver://localhost:1433;databaseName=master;encrypt=false;trustServerCertificate=true
- Download the Microsoft JDBC driver when prompted.
- Click Test Connection.
- Click OK.
Create a new database:
CREATE DATABASE [sqlserver-demo];
GO
Switch to it:
USE [sqlserver-demo];
GO
If the database does not appear immediately, right-click the connection and select Synchronize (or Refresh).
Stop the container
docker stop sqlserver
Start it again
docker start sqlserver
Remove the container
docker rm -f sqlserver
Note: Removing the container deletes the SQL Server instance. To preserve data between recreations, mount a Docker volume.
메타데이터
- post_id
- ee0c7ba7cfaa
- slug
- running-microsoft-sql-server-in-docker-on-ubuntu-ee0c7ba7cfaa
- url
- https://medium.com/@khatiwadasandesh501/running-microsoft-sql-server-in-docker-on-ubuntu-ee0c7ba7cfaa
- canonical_url
- https://medium.com/@khatiwadasandesh501/running-microsoft-sql-server-in-docker-on-ubuntu-ee0c7ba7cfaa
- author_url
- https://medium.com/@khatiwadasandesh501
- status
- ok
- fetched_at
- 2026-09-21 14:15:59