在docker中安装Powercli的问题

在docker中安装Powercli的问题

本文介绍了在docker中安装Powercli的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在php docker映像上安装了PowerShell,现在尝试安装VMWare PowerCLI我在第44行出现以下错误

I have installed PowerShell on php docker image and now trying to install VMWare PowerCLII am getting the following error on line 44

ParserError:
Line |
   1 |  Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP  -Confirm:
     |                                                                     ~
     | Parameter -Confirm: requires an argument.

ERROR: Service 'app' failed to build: The command '/bin/sh -c pwsh -c "Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false -Confirm:$false"' returned a non-zero code: 1

第44行: RUN pwsh -c" Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $ false -Confirm:$ false"

这是我的docker文件

This is my docker file

FROM php:7.4-fpm

# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/

# 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

# 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

#Install VMWare PowerCLI
RUN pwsh -c "Install-Module -Name VMware.PowerCLI -Scope CurrentUser"
RUN pwsh -c "Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false -Confirm:$false"
RUN pwsh -c "Set-PowerCLIConfiguration -Scope User -InvalidCertificateAction Ignore"

# Clear cache
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

# Change current user to www
USER www

# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]

我不知道如何解决.非常感谢您的帮助.

I could not figure how to resolve. Any help is much appreciated.

更新要消除先前的错误,我使用了0而不是$ false.修改后的dockerfile如下:

UpdateTo remove the previous error I used 0 instead of $falseThe modified the dockerfile is as below:

FROM php:7.4-fpm

# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/

# 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

# 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

#Install VMWare PowerCLI
RUN pwsh -c "Save-Module -Name VMware.PowerCLI -Path ~/"
RUN pwsh -c "Install-Module -Name VMware.PowerCLI -Scope CurrentUser -Force"
RUN pwsh -c "Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP 0 -Confirm:0"
RUN pwsh -c "Set-PowerCLIConfiguration -Scope User -InvalidCertificateAction Ignore -Confirm:0"
RUN pwsh -c "Get-Module -ListAvailable VMware.PowerCLI"
RUN pwsh -c "Import-Module VMware.PowerCLI"

现在错误如下:

Exception: VMware.VimAutomation.HorizonView module is not currently supported on the Core edition of PowerShell.
ERROR: Service 'app' failed to build: The command '/bin/sh -c pwsh -c "Import-Module VMware.PowerCLI"' returned a non-zero code: 1

推荐答案

似乎没有VMware.VimAutomation.Horizo​​nView和其他依赖项,则无法安装整个PowerCLI模块.

It seems without VMware.VimAutomation.HorizonView and others' dependencies entire PowerCLI modules cannot be installed.

因此,我没有安装整个PowerCLI及其相关模块,而是只安装了所需的模块:

So, Instead of installing the entire PowerCLI and its dependant modules as a whole, I installed only required modules as:

运行pwsh-命令Get-Module -ListAvailable VMware.VimAutomation.Core |导入模块.

或者,您也可以在下面使用它来仅导入所需的模块.感谢 Scepticalist :

Alternatively, you can also use below to only import the modules you need. Thanks to Scepticalist:

运行pwsh-命令'导入模块-名称VMware.VimAutomation.Core -Scope CurrentUser'

这解决了这个问题.

这篇关于在docker中安装Powercli的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:16