Issue with installation of powercli in docker

你说的曾经没有我的故事 提交于 2021-01-07 02:45:47

问题


I have installed PowerShell on php docker image and now trying to install VMWare PowerCLI I 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

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

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.

Update To remove the previous error I used 0 instead of $false The 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"

Now the error is as follows:

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

回答1:


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

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

RUN pwsh -Command Get-Module -ListAvailable VMware.VimAutomation.Core | Import-Module.

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

RUN pwsh -Command 'Import-Module -Name VMware.VimAutomation.Core -Scope CurrentUser'

This solves the issue.



来源:https://stackoverflow.com/questions/64910004/issue-with-installation-of-powercli-in-docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!