Home:ALL Converter>Import-Module in the Docker PowerShell image

Import-Module in the Docker PowerShell image

Ask Time:2017-11-20T07:09:57         Author:user1795832

Json Formatter

I'm building a Docker image based from microsoft/powershell:ubuntu16.04. It builds properly without any error, however when I go to use it it doesn't have the imported module that I stated in the Dockerfile (which is a psd1 file from a GitHub repo cloned in the image.

I tried with a simple import of Microsoft's powershell management as well (seen below), and it also doesn't get imported. I ran the image interactively and the commands one by one and everything imported fine, so I don't know why it doesn't work through the Dockerfile build itself.

FROM microsoft/powershell:ubuntu16.04
WORKDIR /workdir

RUN pwsh -command "Import-Module Microsoft.PowerShell.Management"

CMD [ "pwsh", "-Command", "Get-Module" ]

Example psd1 file

FROM microsoft/powershell:ubuntu16.04

RUN apt-get update && apt-get install git -y
RUN git clone https://github.com/DTW-DanWard/PowerShell-Beautifier.git
RUN cp -a PowerShell-Beautifier/src/. /opt/microsoft/powershell/6.0.0-rc/Modules

ENTRYPOINT [ "pwsh", "-c" ]
CMD [ "Get-Help", "Edit-DTWBeautifyScript" ]

Author:user1795832,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/47383009/import-module-in-the-docker-powershell-image
yy