Install PowerShell On a Docker Image With Dockerfile

This PowerShell and Docker post will show how we install PowerShell on a Docker container running Ubuntu using a Dockerfile.

Building images with Dockerfile is something that gives DevOps engineers and Developers greater control over the deployment. Dockerfile allows us to build images that are custom and tailored to our needs.

Dockerfile

In the following Dockerfile code, I build a Docker image using Ubuntu latest image and installing the latest PowerShell 7 image.

The last line is optional, and in that line, I run the RUN statement with parameters. The line runs a PowerShell 7 command that prints out the version of PowerShell.

FROM ubuntu 
ENV builddir=build
RUN mkdir \${builddir}
RUN apt-get update
RUN apt-get install -y wget apt-transport-https software-properties-common
RUN wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN apt-get update
RUN add-apt-repository universe
RUN apt-get install -y powershell
RUN ["pwsh", "-command" ,"$psversiontable"]


To build the image, please visit the following post.


Posted

in

,

by