1

I have issues connecting with MSSQL Server Management Studio to my running docker container.

A beginner in docker.

I have created a following docker-compose.yml file:

version: '3.4'

services:
  sqlserver:
    image: "mcr.microsoft.com/mssql/server:2017-latest"
    volumes:
      - /var/lib/docker/volumes/sql_volume/_data
    environment:
      ACCEPT_EULA: "Y"
      SA_PASSWORD: "pa55w0rd!"
      MSSQL_PID: "Express"
    ports:
      - "1533:1534"
  adventureworks_service:
    image: ${DOCKER_REGISTRY-}adventureworksservice
    build:
      context: .
      dockerfile: AdventureWorks_Service/Dockerfile

this docker file should start a MSSQL Database and the adventureworks_service project located in my solution.

this docker-compose is located in it's own Docker project, in the solution. created with the "add docker support" for my Web API project

assuming everything is correctly setup, I should be able to connect to the sql server on localhost:1533, using SQL server authentication with login Express and password pa55w0rd!.

I get following error right after attempting to connect (no timeouts, etc.)

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider : TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host) (Microsoft SQL Server, Error: 10054)

Does anyone know how I can access this server / container?

Thanks in advance

2
  • using SQL server authentication with login Express and password pa55w0rd!. Its login SA and NOT Express. Commented Sep 6, 2021 at 13:59
  • I'm having same issues with login as SA, as well. I'm able to connect to the server using docker exec -it <container_id|container_name> /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P <your_password> in Powershell. This issue only persists when connecting to container spun using docker-compose.yaml. When run using docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=yourStrong(!)Password" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest, I'm able to connect from SSMS. Commented Dec 30, 2021 at 6:53

3 Answers 3

1

The port in mssql should be 1433 rather than 1534, try this

version: '3.4'

services:
  sqlserver:
    image: "mcr.microsoft.com/mssql/server:2017-latest"
    volumes:
      - /var/lib/docker/volumes/sql_volume/_data
    environment:
      ACCEPT_EULA: "Y"
      SA_PASSWORD: "pa55w0rd!"
      MSSQL_PID: "Express"
    ports:
      - "1433:1433"   # the port behind should always be 1433

  adventureworks_service:
    image: ${DOCKER_REGISTRY-}adventureworksservice
    build:
      context: .
      dockerfile: AdventureWorks_Service/Dockerfile

then your connection string should be like this

Data Source=sqlserver,1433;User Id=SA;Password=pa55w0rd!
Sign up to request clarification or add additional context in comments.

Comments

0

Try adding network_mode: "host" to your compose file.

version: '3.4'

services:
  sqlserver:
    image: "mcr.microsoft.com/mssql/server:2017-latest"
    volumes:
      - /var/lib/docker/volumes/sql_volume/_data
    environment:
      ACCEPT_EULA: "Y"
      SA_PASSWORD: "pa55w0rd!"
      MSSQL_PID: "Express"
    ports:
      - "1533:1534"
    network_mode: "host"

  adventureworks_service:
    image: ${DOCKER_REGISTRY-}adventureworksservice
    build:
      context: .
      dockerfile: AdventureWorks_Service/Dockerfile

1 Comment

I'm having same issues. Tried this, but not working.
0

If you still have this error in your SSMS, make sure that you are using correct host name with port it should be localhost,1433 with comma

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.