【发布时间】:2020-11-23 02:22:31
【问题描述】:
我正在尝试在 php docker 映像中安装 powercli,以便可以使用 laravel 将报告发布到网页。已安装 Powershell。但导入模块时 PowerCLI 安装失败并出现以下错误。只有导入模块才能连接服务器。
Exception: VMware.VimAutomation.HorizonView module is not currently supported on the Core edition of PowerShell.
Dockerfile
FROM php:7.4-fpm
.
.
.
# Download the Microsoft repository GPG keys
RUN wget https://packages.microsoft.com/config/debian/10/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
# Start PowerShell
#RUN pwsh
# Allow installation from PSGallery
RUN pwsh -Command 'Set-PSRepository -Name PSGallery -InstallationPolicy Trusted'
# Install PowerCLI, PowervRA, Vester
RUN pwsh -Command 'Install-Module -Name VMware.PowerCLI -Scope CurrentUser'
RUN pwsh -Command 'Install-Module -Name PowervRA -Confirm:$false'
RUN pwsh -Command 'Install-Module -Name Vester -Confirm:$false'
# Disable CEIP warning
RUN pwsh -Command 'Set-PowerCLIConfiguration -ParticipateInCEIP $false -Confirm:$false'
# Set InvalidCertificateAction
RUN pwsh -Command 'Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false'
RUN pwsh -c 'Import-Module VMware.PowerCLI'
.
.
.
docker-compose
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: vapp
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./powershell/Modules/:/usr/local/share/powershell/Modules/
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
.
.
.
在容器上手动测试时它可以工作。 请查看 dockerfile 是否有问题。
更新 1 现在我更新了 docker 文件如下:
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
RUN pwd
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libonig-dev \
locales \
libzip-dev \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
wget \
apt-utils
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl mysqli
RUN docker-php-ext-configure gd --enable-gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-enable mysqli
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
#########################
RUN pwd
# Download the Microsoft repository GPG keys
RUN wget https://packages.microsoft.com/config/debian/10/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
# Start PowerShell
#RUN pwsh
# Allow installation from PSGallery
SHELL ["pwsh", "-command"]
RUN Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
#RUN Install-Module VMware.VimAutomation.Core -Confirm:$false
#RUN Import-Module VMware.VimAutomation.Core; Get-Module
#RUN Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
##RUN connect-viserver 10.21.24.19
RUN mkdir -p ./powershell/Modules
RUN wget https://download3.vmware.com/software/vmw-tools/powerclicore/PowerCLI_Core.zip ~/.local/share/powershell/Modules
RUN unzip -o PowerCLI_Core.zip && unzip -o 'PowerCLI.*.zip' -d ./powershell/Modules
RUN cd ./powershell/Modules
RUN pwd
RUN ls -la
RUN Get-Module -ListAvailable VMware.VimAutomation.Core | Import-Module
RUN $env:PSModulePath = $env:PSModulePath + ":powershell/Modules"
RUN mkdir -p /root/.config/powershell
RUN touch /root/.config/powershell/Microsoft.PowerShell_profile.ps1
RUN echo "Get-Module -ListAvailable PowerCLI* | Import-Module" >> /root/.config/powershell/Microsoft.PowerShell_profile.ps1
SHELL ["/bin/sh", "-c"]
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
【问题讨论】:
-
PowerCLI 通常也需要核心元素,而不仅仅是 Horizon 的特定模块。如果你只运行
Import-Module VMware.PowerCLI会发生什么? -
它失败并出现同样的错误。我不需要 HorizonView。我正在检查
RUN pwsh -c Import-Module VMware.PowerCLI -Function VMware.VimAutomation.HorizonView是否跳过它。 -
RUN pwsh -c 'Import-Module VMware.PowerCLI -ErrorAction Continue'也失败了 -
如果我跳过
RUN pwsh -c 'Import-Module VMware.PowerCLI这一行,构建成功。但是找不到命令。我觉得这是因为模块没有加载。有没有办法解决如何导入模块? -
模块已安装,错误在于导入不受支持的子模块。您可以编辑 .psd 以将其从加载列表中删除。在 Powershell 的安装路径中查找
VMware.PowerCLI.psd1并编辑掉模块。
标签: docker powershell