Docker connect SQL Server container non-zero code: 1
Asked Answered
G

8

32

I'm trying to create a SQL Server container from a docker-compose.yml but when I run it, it directly stops with some errors. Note: it's running on an Apple M1 chip with docker Preview

docker-compose.yml:

version: "3.7"
services:
  sql-server-db:
    container_name: sql-server-db
    image: mcr.microsoft.com/mssql/server:2019-latest
    ports: 
      - "1433:1433"
    environment: 
      SA_PASSWORD: "ApplePassDockerConnect"
      ACCEPT_EULA: "Y"

The errors I'm getting:

sql-server-db | /opt/mssql/bin/sqlservr: Invalid mapping of address 0x40092b8000 in reserved address space below 0x400000000000. Possible causes:

sql-server-db | 1) the process (itself, or via a wrapper) starts-up its own running environment sets the stack size limit to unlimited via syscall setrlimit(2);

sql-server-db | 2) the process (itself, or via a wrapper) adjusts its own execution domain and flag the system its legacy personality via syscall personality(2);

sql-server-db | 3) sysadmin deliberately sets the system to run on legacy VA layout mode by adjusting a sysctl knob vm.legacy_va_layout.

sql-server-db |

sql-server-db exited with code 1

Godhead answered 21/12, 2020 at 19:12 Comment(1)
I've filed a suggestion on this topic (SQL Server support for Apple's M1 chips) at MS's feedback site. It can be found here: feedback.azure.com/d365community/idea/…Crinkle
M
27

You cant really use mcr.microsoft.com/mssql/server:2019-latest containers on M1 because MSSQL DB does not support ARM architecture. The only way I found - is to use Azure SQL container that supports ARM and can be run on M1.

Here my docker-compose.yml config example:

version: "3.9"

services:
    # Database instance
    mssql:
      image: mcr.microsoft.com/azure-sql-edge:latest
      volumes:
        - events_mssql:/var/opt/mssql
      ports:
        - 1433:1433
      environment:
        - ACCEPT_EULA=1
        - MSSQL_SA_PASSWORD=Passw@rd

volumes:
    events_mssql:

You will be able to connect to this DB using username: sa, password: Passw@rd and database: master. If you want other db name - you can create a new one using SQL: CREATE DATABASE TestDB

This database has the same API as MSSQL DB, so it works with pyodbc (not supported on M1) and pymssql libraries.

If you are using it locally on your M1 machine - consider using pymssql library for connection to Azure SQL DB. Here my answer on issue with pyodbc https://mcmap.net/q/454517/-pyodbc-on-m1-macs

Maurizia answered 2/4, 2021 at 13:14 Comment(11)
@Eric what exactly doesn't work? What error do you have?Outplay
The indentation seems to be off. But is ok, I don't need this anymore. I am switching to postgres and I was able to make that work.Neoterism
I tried this for a test proj on my M1 mac and it worked fine.Montoya
using Docker environment variables in .sql file does not seem to work for me. Is $(MSSQL_DB) the correct format?Noli
@Noli you are right. I just realized that this script doesn't work in an azure container and it was intended for mssql container. I updated the answer and added the recipe on how to create a different DB in the Azure container.Outplay
Btw there is discussion is going on in the GitHub repo regarding ARM arch support of mssql dbOutplay
Azure Edge does not support GeoPoints (because the docker container does not come with any DotNet runtime)Antoniaantonie
I've filed a suggestion on this topic (SQL Server support for Apple's M1 chips) at MS's feedback site. It can be found here: feedback.azure.com/d365community/idea/…Crinkle
An important issue of this approach is that the mssql-tools are not available. This is the note from hub.docker.com/_/microsoft-azure-sql-edge: [!NOTE] sqlcmd tool is not available inside the ARM64 version of SQL Edge containers.Labellum
I've tried to use azure-sql-edge but getting Error: Common Language Runtime(CLR) is not enabled on this instance & enabling this setting is not supported on the azure-sql-edge. So anyone knows any workaround for this?Angi
I wonder if the image has changed. I was having success with Azure Edge, but now I'm getting the same segfault as I do with MSSQL.Delfinadelfine
D
27

Docker now supports the experimental feature of using Rosetta (interpretation layer) for emulating x86 applications on amd64 architecture. This fixed the issue for me. enter image description here

Defense answered 17/3, 2023 at 14:1 Comment(3)
This was able to get me up and running on my M2 chip: builtin.com/software-engineering-perspectives/…Lorikeet
This is the way. (for now)Lepanto
This worked for me. Enable the Rosetta checkbox, restart Docker, and you're good to go.Fulfil
P
5

SQL Image for Apple Chip M1 are not containerised yet, but we can use azure-sql-edge.

I have also tried MSSQL image for Apple M1 Chip, but same error.

Using azure-sql-edge, I am able to use MSSQL on Apple BigSur OS with M1 Chip

You can go through this article https://medium.com/geekculture/docker-express-running-a-local-sql-server-on-your-m1-mac-8bbc22c49dc9

Don't forget to mark it Answered, if it helps you.

Photoemission answered 8/8, 2021 at 13:10 Comment(1)
This worked for me on a Mac M2, as well. !Dyslogistic
D
1

As others have noted, Azure SQL Edge Server is a workaround for the M1 issues of MSSQL Server. However, at the moment, the :latest tag of Azure SQL Edge Server has the same segfault as MSSQL server. mcr.microsoft.com/azure-sql-edge:1.0.6 works on M1, though.

docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=1' -e 'MSSQL_SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 --name azuresqledge -d mcr.microsoft.com/azure-sql-edge:1.0.6
Delfinadelfine answered 1/7, 2022 at 11:5 Comment(1)
It is not working with this version, I have tried it version: "3.1" services: mssql: image: mcr.microsoft.com/azure-sql-edge:1.0.6 container_name: mssql volumes: - events_mssql:/var/opt/mssql - ./setup.sql:/usr/config/setup.sql ports: - 1433:1433 environment: - ACCEPT_EULA=Y - MSSQL_SA_PASSWORD=Passw@rd - MSSQL_PID=Developer - MSSQL_DB=events_service - MSSQL_USER=SA - MSSQL_PASSWORD=Passw@rd - MSSQL_DB_AUDIT_LOG=events_service_audit_log volumes: events_mssql:Toomey
A
1
The latest version of Azure SQL Edge works for me on M1. 
  database:
    container_name: database
    image: mcr.microsoft.com/azure-sql-edge:latest
    ports:
      - 1433:1433
    environment:
      - ACCEPT_EULA=Y
      - MSSQL_SA_PASSWORD=<YourStrong@Passw0rd>

Autogamy answered 12/3, 2023 at 4:24 Comment(0)
S
1

On MachBook M3 Max - enable Use Rosetta for x86/amd64 emulation on Apple Silicon enter image description here

Sorenson answered 10/3 at 11:48 Comment(0)
P
0

So...this may not be related to your particular issue. I have a feeling it won't fix it for you, because your issue sounds much lower level (as you suspect) but it's worth a shot.

I tried copy-pasting your exact docker-compose file and running it on my machine (windows desktop), I also get exited with code 1.

The only thing that seemed to fix it was using a more complex password.

I tested this multiple times in a row...I tested your password, and it failed. I tested a complex password, and it worked fine.

So I suggest using a more complex password. The password I tested with was 6Xy3LkV7!9lo2^h

Pawpaw answered 21/12, 2020 at 21:58 Comment(1)
that didn't fixed the issue but thanks for your suggestionGodhead
S
0

You can use azure-sql-edge image.

After a couple of hours, I am able to find this alternative:

After opening Docker and removing containers and images, ran in terminal:

docker pull mcr.microsoft.com/azure-sql-edge:latest

sudo docker run -e "ACCEPT_EULA=1" -e "MSSQL_SA_PASSWORD=Pass123" -e "MSSQL_PID=Developer" -e "MSSQL_USER=SA" -p 1433:1433 -d --name=sql mcr.microsoft.com/azure-sql-edge

Then use "localhost,1433" as server, "SA" as username, "Pass123" as password.(Without quotes)

Shakitashako answered 30/12, 2023 at 14:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.