可以使用‘Microsoft SQL Server’停靠容器创建卷吗?

ikfrs5lh  于 2022-10-03  发布在  SQL Server
关注(0)|答案(3)|浏览(170)

我在我的Linux机器上运行以下命令,并想要附加一个卷,就像在MySQL中一样

docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=12345678' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest
83qze16e

83qze16e1#

您也可以在Microsoft SQL Server上附加卷,如Microsoft文档中所述:

docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=12345678' -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:2017-latest

使用上述命令,您可以将容器的三个文件夹挂载到主机目录:

  • <host directory>/data:/var/opt/mssql/data
  • <host directory>/log:/var/opt/mssql/log
  • <host directory>/secrets:/var/opt/mssql/secrets

您还可以使用数据卷容器,而不是已装载的主机目录:

docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=12345678' -p 1433:1433 -v sqlvolume:/var/opt/mssql -d mcr.microsoft.com/mssql/server:2017-latest
zfycwa2u

zfycwa2u2#

您可以将其用作docker-compose.yaml文件:

services:
  mssql:
    image: mcr.microsoft.com/mssql/server:2022-latest
    ports:
      - 1433:1433
    volumes:
      - ./data:/var/opt/mssql/data
      - ./log:/var/opt/mssql/log
      - ./secrets:/var/opt/mssql/secrets
    environment:
      - ACCEPT_EULA=Y
      - SA_PASSWORD=123456789

然后,为防止出现权限被拒绝错误,请创建Data、Log和Secret文件夹并更改其权限:

mkdir data && sudo chown 10001 data
mkdir log && sudo chown 10001 log
mkdir secrets && sudo chown 10001 secrets

最后,使用docker-compose up -d启动容器。

fykwrbwg

fykwrbwg3#

检查文件/var/opt/mssql/mssql.conf,您将获得[filelocation]部分下所有数据的位置:

[filelocation]

# defaultbackupdir                # Default directory for backup files

# defaultdatadir                  # Default directory for data files

# defaultdumpdir                  # Default directory for crash dump files

# defaultlogdir                   # Default directory for log files

# errorlogfile                    # Error log file location

# masterdatafile                  # Master database data file location

# masterlogfile                   # Master database log file location

相关问题