Hey folks! I'm trying to set up a Docker container that utilizes a Microsoft image and needs PowerShell for running some scripts. I'm hitting a snag because it seems like PowerShell isn't pre-installed in the container environment. Here's what I've tried:
1. Using the Windows Server Core image, which should have PowerShell.
2. Downloading and installing PowerShell Core manually.
3. Trying out different base images.
Here's my current Dockerfile:
```dockerfile
FROM mcr.microsoft.com/windows/servercore:ltsc2022
# Download PowerShell Core
ADD https://github.com/PowerShell/PowerShell/releases/download/v7.4.1/PowerShell-7.4.1-win-x64.zip C:/PowerShell.zip
# Extract PowerShell Core using PowerShell
SHELL ["C:WindowsSystem32WindowsPowerShellv1.0powershell.exe", "-Command"]
RUN Expand-Archive -Path C:PowerShell.zip -DestinationPath C:PowerShell;
Remove-Item -Path C:PowerShell.zip
# Set PowerShell Core as the shell
SHELL ["C:PowerShellpwsh.exe", "-Command"]
# Install MicrosoftTeams module
RUN Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force;
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted;
Install-Module -Name MicrosoftTeams -Force -AllowClobber
# Set working directory
WORKDIR C:/app
# Copy script
COPY service.ps1 .
# Expose port
EXPOSE 8081
# Run script
CMD ["C:PowerShellpwsh.exe", "-File", "C:/app/service.ps1"]
```
Any advice or insights on how to get PowerShell running smoothly in my Docker setup would be awesome!
2 Answers
Have you considered using a Linux-based image instead? There’s a PowerShell image for Linux available that might suit your needs just as well. You can find installation instructions here: https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux?view=powershell-7.5. Just a thought if you're open to switching up your base!
That's an interesting approach! Running Windows in a Docker container isn’t super common, but it can definitely be done. The reason many opt for VMs is compatibility and ease of use, but if your project's modular structure works better with containers, go for it! You mentioned needing to run PowerShell scripts, right? Just make sure your base image has all dependencies installed first, otherwise it can be a headache.
I'm really just focused on running PowerShell, so I’m flexible with the base image. I'm more concerned about having the ability to install the necessary modules.