我希望能够在SQL Server Docker实例中运行一些交互式命令。由于我不熟悉bash并且具有一些PowerShell知识,因此我将使用PowerShell Core。
如何在SQL Server docker映像之上安装PowerShell Core?
答案 0 :(得分:0)
创建以下Dockerfile(SQL Server 2019映像示例,大部分内容来自here):
FROM mcr.microsoft.com/mssql/server:2019-latest AS base
# This is required since the instance uses mssql user and the following command require root or sudo
# This is used to avoid installing sudo
USER root
# Download the Microsoft repository GPG keys
RUN wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
# Register the Microsoft repository GPG keys
RUN dpkg -i packages-microsoft-prod.deb
# Update the list of products
RUN apt-get update
# Install PowerShell
RUN apt-get install -y powershell
# Revert back to default user used by SQL instance
USER mssql
要与docker实例进行交互工作,请显式使用root
用户(source):
docker exec -u 0 -it mssqlcontainer pwsh
PowerShell 7.0.0
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/powershell
Type 'help' to get help.
PS /> $PSVersionTable.PSVersion
Major Minor Patch PreReleaseLabel BuildLabel
----- ----- ----- --------------- ----------
7 0 0