Skip to content

rchardptrsn/MSSQL-Docker-Container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker MSSQL Server

Pull image:

docker pull mcr.microsoft.com/mssql/server

Run container:

docker run \
-e 'ACCEPT_EULA=Y' \
-e 'SA_PASSWORD=Password1!' \
-e 'MSSQL_PID=Express' \
--name sqlserver \
-p 1433:1433 -d mcr.microsoft.com/mssql/server:latest

# Enter the container:
docker exec -it sqlserver "bash"
# Launch sqlcmd from container command line:
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "Password1!"
# Interact with the database from the command line
CREATE DATABASE heroes
GO
USE heroes
CREATE TABLE HeroValue (id INT, name VARCHAR(50))
INSERT into HeroValue VALUES (1, "Wonder Woman")
GO
SELECT * FROM HeroValue;
GO

Dockerfile

Build the docker image

docker build -t mssql:dev . 

Run the image and create a container

docker run \
-e 'ACCEPT_EULA=Y' \
-e 'SA_PASSWORD=Password1!' \
-e 'MSSQL_PID=Express' \
--name sqlserver \
-p 1433:1433 \
-d mssql:dev

Access the container to confirm it is working.

docker exec -it sqlserver "bash"
# from container command line
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "Password1!" -d heroes
# Run from sqlcmd command line
# For some reason, it only shows the last entry, but they are all there.
SELECT * FROM HeroValue;
GO

.NET Core connection string

"ConnectionStrings": {
    "DockerDB": "Server=localhost,1433;Database=heroes;User ID=SA;Password=Password1!"
  }

About

Dockerfile with scripts and test data.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published