Share via

Could not create database on SQLserver hosted from docker container

Yogi 356 Reputation points
2026-02-15T12:31:20.91+00:00

I have created an sql server from a docker container by the below command:

docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=vV5r9tn0M4@" ^
-p 1433:1433 ^
-v D:\SQL\Data:/var/opt/mssql/data ^
-v D:\SQL\log:/var/opt/mssql/log ^
-v D:\SQL\secrets:/var/opt/mssql/secrets ^
-d mcr.microsoft.com/mssql/server:2025-latest

The Microsoft article link - https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-docker-container-configure?view=sql-server-ver17&pivots=cs1-cmd

On SQL Server management studio I am able to connect with the sql server running from docker container. However I could not create a new database in the server. See the attached screenshot:

Screenshot 2026-02-15 173634

In the above screenshot you can see I am trying to create a database called test but it is failing.

The error message is:

-- Source - https://stackoverflow.com/q/79889672
-- Posted by yogihosting
-- Retrieved 2026-02-15, License - CC BY-SA 4.0

===================================

Create failed for Database 'test'.  (Microsoft.SqlServer.Smo)

------------------------------
For help, click: https://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=17.100.73.0&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+Database&LinkId=20476

------------------------------
Program Location:

   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImpl()
   at Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseData.DatabasePrototype.ApplyChanges(Control marshallingControl, RunType _)
   at Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabase.DoPreProcessExecution(RunType runType, ExecutionMode& executionResult)
   at Microsoft.SqlServer.Management.SqlMgmt.SqlMgmtTreeViewControl.DoPreProcessExecutionAndRunViews(RunType runType)
   at Microsoft.SqlServer.Management.SqlMgmt.SqlMgmtTreeViewControl.ExecuteForSql(PreProcessExecutionInfo executionInfo, ExecutionMode& executionResult)
   at Microsoft.SqlServer.Management.SqlMgmt.SqlMgmtTreeViewControl.Microsoft.SqlServer.Management.SqlMgmt.IExecutionAwareSqlControlCollection.PreProcessExecution(PreProcessExecutionInfo executionInfo, ExecutionMode& executionResult)
   at Microsoft.SqlServer.Management.SqlMgmt.ViewSwitcherControlsManager.RunNow(RunType runType, Object sender)

===================================

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

------------------------------
Program Location:

   at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType, Boolean retry)
   at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType, Boolean retry)
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.ExecuteNonQuery(StringCollection queries, Boolean includeDbContext, Boolean executeForAlter)
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImplFinish(StringCollection createQuery, ScriptingPreferences sp)
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImpl()

===================================

MODIFY FILE encountered operating system error 31(A device attached to the system is not functioning.) while attempting to expand the physical file '/var/opt/mssql/data/test.mdf'.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors. (Framework Microsoft SqlClient Data Provider)

------------------------------
For help, click: https://docs.microsoft.com/sql/relational-databases/errors-events/mssqlserver-5149-database-engine-error

------------------------------
Server Name: localhost,1433
Error Number: 5149
Severity: 16
State: 3
Line Number: 1


------------------------------
Program Location:

   at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at Microsoft.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
   at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException)
   at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType, Boolean retry)

If I remove the volumes from the docker command then everything is working. So this is something related to docker volumes and I am not able to figure the problem. Any solution??

SQL Server Database Engine
0 comments No comments

Answer recommended by moderator
  1. Akhil Gajavelly 1,810 Reputation points Microsoft External Staff Moderator
    2026-03-05T05:56:57.5766667+00:00

    Hi @Yogi ,

    Since the container works with named volumes, SQL Server itself is fine. The problem is the Windows bind-mounted folders.

    Please try recreating the folders and ensure they are fully writable by Docker:

    1. Delete the existing folders D:\SQL\Data, D:\SQL\log, D:\SQL\secrets.
    2. Recreate them using PowerShell: mkdir D:\SQL\Data                
      mkdir D:\SQL\log                
      mkdir D:\SQL\secrets                
      icacls D:\SQL /grant Everyone:(OI)(CI)F /T
    3. Restart Docker Desktop.
    4. Run the container again: docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=vV5r9tn0M4@" ^               
      -p 1433:1433 ^               
      -v D:/SQL/Data:/var/opt/mssql/data ^               
      -v D:/SQL/log:/var/opt/mssql/log ^               
      -v D:/SQL/secrets:/var/opt/mssql/secrets ^               
      -d mcr.microsoft.com/mssql/server:2025-latest

    This ensures the mounted NTFS folders allow write access for the Linux mssql process inside the container, which resolves the database creation failure.

    Thanks,
    Akhil.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 83,816 Reputation points
    2026-02-15T23:11:35.6933333+00:00

    Did you install docker with WSL 2 or Hyper-V? If Hyper-V, you need to set the mount folder permission on the host. If WSL 2, it assumed the folders are owned by the user account running docker.


  2. Erland Sommarskog 133.7K Reputation points MVP Volunteer Moderator
    2026-02-15T13:02:34.9066667+00:00

    I have not used Docker on Windows, and it was quite some time I played with it on Unix. But I note on the page you linked to that it says:

    docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<password>" ^
    -p 1433:1433 ^
    -v <host directory>/data:/var/opt/mssql/data ^
    -v <host directory>/log:/var/opt/mssql/log ^
    -v <host directory>/secrets:/var/opt/mssql/secrets ^
    -d mcr.microsoft.com/mssql/server:2022-latest
    
    
    

    With forward slashes throughout, whereas you have backslashes in your command. It could be that the page in Microsoft Learn has a typo, but it could be something to try.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.