使用 Docker 卷持久化 mcr.microsoft.com/mssql/server:2019-latest 容器时权限被拒绝

Posted

技术标签:

【中文标题】使用 Docker 卷持久化 mcr.microsoft.com/mssql/server:2019-latest 容器时权限被拒绝【英文标题】:Permission denied when persisting a container of mcr.microsoft.com/mssql/server:2019-latest using Docker volumes 【发布时间】:2020-05-10 03:57:59 【问题描述】:

在 Windows 10 上,使用 Docker 桌面版本 2.1.0.5。

我已经成功使用了图像microsoft/mssql-server-linux:2017-latest,但是自从it is deprecated 之后,我将其更改为mcr.microsoft.com/mssql/server:2019-latest,在那里我遇到了问题。

我将数据库服务定义为:

version: '3.4'

services:

  sql.data:
    container_name: tvq_db
    image: mcr.microsoft.com/mssql/server:2019-latest

    environment:
      - SA_PASSWORD=Pass_word
      - ACCEPT_EULA=Y

    ports:
      - "1433:1433"

    volumes:
      - $APPDATA/MyServiceDB/mssql:/var/opt/mssql

使用此设置,我的 ASP.NET Core 应用程序无法连接到数据库服务,当我检查数据库容器的日志时,我看到许多 Permission denied 错误。日志如下:

This program has encountered a fatal error and cannot continue running at Thu Jan 23 19:35:01 2020
SQL Server 2019 will run as non-root by default.
The following diagnostic information is available:

         Reason: 0x00000006
This container is running as user mssql.
        Message: Kernel bug check
        Address: 0x6b847e90
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
     Parameters: 0x10861f590

    Stack Trace:
                 000000006b9358de
Ubuntu 16.04.6 LTS
                 000000006b847eeb
                 000000006b83457e
Capturing core dump and information to /var/opt/mssql/log...
                 000000006b843155
                 000000006b843326
                 000000006b933bac
                 000000006b93271f
                 000000006b975c31
        Process: 12 - sqlservr
         Thread: 16 (application thread 0x4)
    Instance Id: 30c43f95-99ae-4690-b94b-4dea47909601
       Crash Id: d810733f-44af-473f-a5b1-13e26bc9d3cd
    Build stamp: 560c56ee7000c721a5dff27fa44f6ea8b3c72562060679d6d4790e8389f46953
   Distribution: Ubuntu 16.04.6 LTS
     Processors: 2
   Total Memory: 2096144384 bytes
      Timestamp: Thu Jan 23 19:35:01 2020
     Last errno: 2
Last errno text: No such file or directory
/bin/cat: /proc/12/maps: Permission denied
/bin/cat: /proc/12/environ: Permission denied
/usr/bin/find: '/proc/12/task/12/fd': Permission denied
/usr/bin/find: '/proc/12/task/12/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/12/ns': Permission denied
/usr/bin/find: '/proc/12/task/13/fd': Permission denied
/usr/bin/find: '/proc/12/task/13/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/13/ns': Permission denied
/usr/bin/find: '/proc/12/task/14/fd': Permission denied
/usr/bin/find: '/proc/12/task/14/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/14/ns': Permission denied
/usr/bin/find: '/proc/12/task/15/fd': Permission denied
/usr/bin/find: '/proc/12/task/15/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/15/ns': Permission denied
/usr/bin/find: '/proc/12/task/16/fd': Permission denied
/usr/bin/find: '/proc/12/task/16/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/16/ns': Permission denied
/usr/bin/find: '/proc/12/task/17/fd': Permission denied
/usr/bin/find: '/proc/12/task/17/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/17/ns': Permission denied
/usr/bin/find: '/proc/12/task/18/fd': Permission denied
/usr/bin/find: '/proc/12/task/18/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/18/ns': Permission denied
/usr/bin/find: '/proc/12/task/19/fd': Permission denied
/usr/bin/find: '/proc/12/task/19/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/19/ns': Permission denied
/usr/bin/find: '/proc/12/task/20/fd': Permission denied
/usr/bin/find: '/proc/12/task/20/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/20/ns': Permission denied
/usr/bin/find: '/proc/12/task/21/fd': Permission denied
/usr/bin/find: '/proc/12/task/21/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/21/ns': Permission denied
/usr/bin/find: '/proc/12/task/22/fd': Permission denied
/usr/bin/find: '/proc/12/task/22/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/22/ns': Permission denied
/usr/bin/find: '/proc/12/task/23/fd': Permission denied
/usr/bin/find: '/proc/12/task/23/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/23/ns': Permission denied
/usr/bin/find: '/proc/12/fd': Permission denied
/usr/bin/find: '/proc/12/map_files': Permission denied
/usr/bin/find: '/proc/12/fdinfo': Permission denied
/usr/bin/find: '/proc/12/ns': Permission denied
/usr/bin/find: '/proc/12/task/12/fd': Permission denied
/usr/bin/find: '/proc/12/task/12/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/12/ns': Permission denied
/usr/bin/find: '/proc/12/task/13/fd': Permission denied
/usr/bin/find: '/proc/12/task/13/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/13/ns': Permission denied
/usr/bin/find: '/proc/12/task/14/fd': Permission denied
/usr/bin/find: '/proc/12/task/14/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/14/ns': Permission denied
/usr/bin/find: '/proc/12/task/15/fd': Permission denied
/usr/bin/find: '/proc/12/task/15/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/15/ns': Permission denied
/usr/bin/find: '/proc/12/task/16/fd': Permission denied
/usr/bin/find: '/proc/12/task/16/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/16/ns': Permission denied
/usr/bin/find: '/proc/12/task/17/fd': Permission denied
/usr/bin/find: '/proc/12/task/17/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/17/ns': Permission denied
/usr/bin/find: '/proc/12/task/18/fd': Permission denied
/usr/bin/find: '/proc/12/task/18/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/18/ns': Permission denied
/usr/bin/find: '/proc/12/task/19/fd': Permission denied
/usr/bin/find: '/proc/12/task/19/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/19/ns': Permission denied
/usr/bin/find: '/proc/12/task/20/fd': Permission denied
/usr/bin/find: '/proc/12/task/20/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/20/ns': Permission denied
/usr/bin/find: '/proc/12/task/21/fd': Permission denied
/usr/bin/find: '/proc/12/task/21/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/21/ns': Permission denied
/usr/bin/find: '/proc/12/task/22/fd': Permission denied
/usr/bin/find: '/proc/12/task/22/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/22/ns': Permission denied
/usr/bin/find: '/proc/12/task/23/fd': Permission denied
/usr/bin/find: '/proc/12/task/23/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/23/ns': Permission denied
/usr/bin/find: '/proc/12/fd': Permission denied
/usr/bin/find: '/proc/12/map_files': Permission denied
/usr/bin/find: '/proc/12/fdinfo': Permission denied
/usr/bin/find: '/proc/12/ns': Permission denied
/usr/bin/find: '/proc/12/task/12/fd': Permission denied
/usr/bin/find: '/proc/12/task/12/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/12/ns': Permission denied
/usr/bin/find: '/proc/12/task/13/fd': Permission denied
/usr/bin/find: '/proc/12/task/13/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/13/ns': Permission denied
/usr/bin/find: '/proc/12/task/14/fd': Permission denied
/usr/bin/find: '/proc/12/task/14/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/14/ns': Permission denied
/usr/bin/find: '/proc/12/task/15/fd': Permission denied
/usr/bin/find: '/proc/12/task/15/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/15/ns': Permission denied
/usr/bin/find: '/proc/12/task/16/fd': Permission denied
/usr/bin/find: '/proc/12/task/16/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/16/ns': Permission denied
/usr/bin/find: '/proc/12/task/17/fd': Permission denied
/usr/bin/find: '/proc/12/task/17/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/17/ns': Permission denied
/usr/bin/find: '/proc/12/task/18/fd': Permission denied
/usr/bin/find: '/proc/12/task/18/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/18/ns': Permission denied
/usr/bin/find: '/proc/12/task/19/fd': Permission denied
/usr/bin/find: '/proc/12/task/19/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/19/ns': Permission denied
/usr/bin/find: '/proc/12/task/20/fd': Permission denied
/usr/bin/find: '/proc/12/task/20/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/20/ns': Permission denied
/usr/bin/find: '/proc/12/task/21/fd': Permission denied
/usr/bin/find: '/proc/12/task/21/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/21/ns': Permission denied
/usr/bin/find: '/proc/12/task/22/fd': Permission denied
/usr/bin/find: '/proc/12/task/22/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/22/ns': Permission denied
/usr/bin/find: '/proc/12/task/23/fd': Permission denied
/usr/bin/find: '/proc/12/task/23/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/23/ns': Permission denied
/usr/bin/find: '/proc/12/fd': Permission denied
/usr/bin/find: '/proc/12/map_files': Permission denied
Thu Jan 23 19:35:02 UTC 2020 Capturing program information
/usr/bin/find: '/proc/12/fdinfo': Permission denied
/usr/bin/find: '/proc/12/ns': Permission denied
/usr/bin/find: '/proc/12/task/12/fd': Permission denied
Thu Jan 23 19:35:02 UTC 2020 Attempting to capture a dump with paldumper
/usr/bin/find: '/proc/12/task/12/fdinfo': Permission denied
WARNING: Capture attempt failure detected
Attempting to capture a filtered dump with paldumper
/usr/bin/find: '/proc/12/task/12/ns': Permission denied
WARNING: Attempt to capture dump failed.  Reference /var/opt/mssql/log/core.sqlservr.12.temp/log/paldumper-debug.log for details
Thu Jan 23 19:35:02 UTC 2020 Attempting to capture a dump with gdb
Thu Jan 23 19:35:02 UTC 2020 Captured a dump with gdb
/usr/bin/find: '/proc/12/task/13/fd': Permission denied
Thu Jan 23 19:35:02 UTC 2020 Capturing program binaries
Thu Jan 23 19:35:02 UTC 2020 Compressing the dump files
/usr/bin/find: '/proc/12/task/13/fdinfo': Permission denied
SQL Server 2019 will run as non-root by default.
This container is running as user mssql.
/usr/bin/find: '/proc/12/task/13/ns': Permission denied
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
/usr/bin/find: '/proc/12/task/14/fd': Permission denied
/usr/bin/find: '/proc/12/task/14/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/14/ns': Permission denied
/usr/bin/find: '/proc/12/task/15/fd': Permission denied
/usr/bin/find: '/proc/12/task/15/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/15/ns': Permission denied
/usr/bin/find: '/proc/12/task/16/fd': Permission denied
/usr/bin/find: '/proc/12/task/16/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/16/ns': Permission denied

/usr/bin/find: '/proc/12/task/17/fd': Permission denied
/usr/bin/find: '/proc/12/task/17/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/17/ns': Permission denied
Ubuntu 16.04.6 LTS
/usr/bin/find: '/proc/12/task/18/fd': Permission denied
/usr/bin/find: '/proc/12/task/18/fdinfo': Permission denied
Capturing core dump and information to /var/opt/mssql/log...
/usr/bin/find: '/proc/12/task/18/ns': Permission denied
/usr/bin/find: '/proc/12/task/19/fd': Permission denied
/usr/bin/find: '/proc/12/task/19/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/19/ns': Permission denied
/usr/bin/find: '/proc/12/task/20/fd': Permission denied
/usr/bin/find: '/proc/12/task/20/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/20/ns': Permission denied
/usr/bin/find: '/proc/12/task/21/fd': Permission denied
/usr/bin/find: '/proc/12/task/21/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/21/ns': Permission denied
/usr/bin/find: '/proc/12/task/22/fd': Permission denied
/usr/bin/find: '/proc/12/task/22/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/22/ns': Permission denied
/usr/bin/find: '/proc/12/task/23/fd': Permission denied
/usr/bin/find: '/proc/12/task/23/fdinfo': Permission denied
/usr/bin/find: '/proc/12/task/23/ns': Permission denied
/usr/bin/find: '/proc/12/fd': Permission denied
/usr/bin/find: '/proc/12/map_files': Permission denied
/usr/bin/find: '/proc/12/fdinfo': Permission denied
/usr/bin/find: '/proc/12/ns': Permission denied
dmesg: read kernel buffer failed: Operation not permitted
No journal files were found.
No journal files were found.
This program has encountered a fatal error and cannot continue running at Thu Jan 23 19:39:21 2020

我尝试了on this issue, such as this one 讨论的步骤,但没有一个解决问题。而且由于该问题在没有适当解决方案的情况下在那里关闭,并且对 Docker 和 MSSQL github 问题上的类似问题没有太多支持,因此我将问题发布在这里。

【问题讨论】:

【参考方案1】:

解决方案:

添加 user: root 部分对我有用。

在主机上运行 ubuntu。

这是我的文件:

docker-compose.yml

version: "3.7"
services:
  sqlserver:
    image: mcr.microsoft.com/mssql/server:2019-latest
    container_name: sqlserver
    user: root   #####################   <<<<<<<<< IMPORTANT!!!!!  ############
    ports:
    #   host-port:container-port 
      - "1433:1433"
    environment:
      # SA_USERNAME: sa
      SA_PASSWORD: Dev1234!
      ACCEPT_EULA: Y
    volumes:
      - ./volumes/data2:/var/opt/mssql/data

已经搜索了几个小时

【讨论】:

【参考方案2】:

我遇到了同样的问题。

见here。

您无法挂载 /var/opt/mssql 相反,您需要挂载 /var/opt/mssql/data

volumes:
  - $APPDATA/MyServiceDB/mssql:/var/opt/mssql/data

【讨论】:

【参考方案3】:

您可以使用以下参数运行 Docker:

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=MyStrongPassword" -u 0:0
-p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest

【讨论】:

以上是关于使用 Docker 卷持久化 mcr.microsoft.com/mssql/server:2019-latest 容器时权限被拒绝的主要内容,如果未能解决你的问题,请参考以下文章

docker容器数据卷

4.docker数据卷管理

Docker数据持久化简述

Docker中的数据卷

使用 Docker 卷持久化 mcr.microsoft.com/mssql/server:2019-latest 容器时权限被拒绝

Docker之七:Docker数据卷管理