0

I want to be able to run some interactive commands inside a SQL Server Docker instance. Since I not familiar with bash and I have some PowerShell knowledge I would use PowerShell Core.

How to install PowerShell Core on top of a SQL Server docker image?

1 Answer 1

3

Create the following Dockerfile (example for SQL Server 2019 image, most content from 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 

To interactively work with the docker instance, explicitly use the root user (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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.