Unpacking Software Livestream

Join our monthly Unpacking Software livestream to hear about the latest news, chat and opinion on packaging, software deployment and lifecycle management!

Learn More

Chocolatey Product Spotlight

Join the Chocolatey Team on our regular monthly stream where we put a spotlight on the most recent Chocolatey product releases. You'll have a chance to have your questions answered in a live Ask Me Anything format.

Learn More

Chocolatey Coding Livestream

Join us for the Chocolatey Coding Livestream, where members of our team dive into the heart of open source development by coding live on various Chocolatey projects. Tune in to witness real-time coding, ask questions, and gain insights into the world of package management. Don't miss this opportunity to engage with our team and contribute to the future of Chocolatey!

Learn More

Calling All Chocolatiers! Whipping Up Windows Automation with Chocolatey Central Management

Webinar from
Wednesday, 17 January 2024

We are delighted to announce the release of Chocolatey Central Management v0.12.0, featuring seamless Deployment Plan creation, time-saving duplications, insightful Group Details, an upgraded Dashboard, bug fixes, user interface polishing, and refined documentation. As an added bonus we'll have members of our Solutions Engineering team on-hand to dive into some interesting ways you can leverage the new features available!

Watch On-Demand
Chocolatey Community Coffee Break

Join the Chocolatey Team as we discuss all things Community, what we do, how you can get involved and answer your Chocolatey questions.

Watch The Replays
Chocolatey and Intune Overview

Webinar Replay from
Wednesday, 30 March 2022

At Chocolatey Software we strive for simple, and teaching others. Let us teach you just how simple it could be to keep your 3rd party applications updated across your devices, all with Intune!

Watch On-Demand
Chocolatey For Business. In Azure. In One Click.

Livestream from
Thursday, 9 June 2022

Join James and Josh to show you how you can get the Chocolatey For Business recommended infrastructure and workflow, created, in Azure, in around 20 minutes.

Watch On-Demand
The Future of Chocolatey CLI

Livestream from
Thursday, 04 August 2022

Join Paul and Gary to hear more about the plans for the Chocolatey CLI in the not so distant future. We'll talk about some cool new features, long term asks from Customers and Community and how you can get involved!

Watch On-Demand
Hacktoberfest Tuesdays 2022

Livestreams from
October 2022

For Hacktoberfest, Chocolatey ran a livestream every Tuesday! Re-watch Cory, James, Gary, and Rain as they share knowledge on how to contribute to open-source projects such as Chocolatey CLI.

Watch On-Demand

Downloads:

880

Downloads of v 0.3.0:

596

Last Update:

14 Oct 2020

Package Maintainer(s):

Software Author(s):

  • Baptiste Cabrera

Tags:

docker container windows linux macos

Bca.Docker

  • 1
  • 2
  • 3

0.3.0 | Updated: 14 Oct 2020

Downloads:

880

Downloads of v 0.3.0:

596

Maintainer(s):

Software Author(s):

  • Baptiste Cabrera

Bca.Docker 0.3.0

Legal Disclaimer: Neither this package nor Chocolatey Software, Inc. are affiliated with or endorsed by Baptiste Cabrera. The inclusion of Baptiste Cabrera trademark(s), if any, upon this webpage is solely to identify Baptiste Cabrera goods or services and not for commercial purposes.

  • 1
  • 2
  • 3

All Checks are Passing

3 Passing Tests


Validation Testing Passed


Verification Testing Passed

Details

Scan Testing Successful:

No detections found in any package files

Details
Learn More

Deployment Method: Individual Install, Upgrade, & Uninstall

To install Bca.Docker, run the following command from the command line or from PowerShell:

>

To upgrade Bca.Docker, run the following command from the command line or from PowerShell:

>

To uninstall Bca.Docker, run the following command from the command line or from PowerShell:

>

Deployment Method:

NOTE

This applies to both open source and commercial editions of Chocolatey.

1. Enter Your Internal Repository Url

(this should look similar to https://community.chocolatey.org/api/v2/)


2. Setup Your Environment

1. Ensure you are set for organizational deployment

Please see the organizational deployment guide

2. Get the package into your environment

  • Open Source or Commercial:
    • Proxy Repository - Create a proxy nuget repository on Nexus, Artifactory Pro, or a proxy Chocolatey repository on ProGet. Point your upstream to https://community.chocolatey.org/api/v2/. Packages cache on first access automatically. Make sure your choco clients are using your proxy repository as a source and NOT the default community repository. See source command for more information.
    • You can also just download the package and push it to a repository Download

3. Copy Your Script

choco upgrade bca-docker -y --source="'INTERNAL REPO URL'" [other options]

See options you can pass to upgrade.

See best practices for scripting.

Add this to a PowerShell script or use a Batch script with tools and in places where you are calling directly to Chocolatey. If you are integrating, keep in mind enhanced exit codes.

If you do use a PowerShell script, use the following to ensure bad exit codes are shown as failures:


choco upgrade bca-docker -y --source="'INTERNAL REPO URL'" 
$exitCode = $LASTEXITCODE

Write-Verbose "Exit code was $exitCode"
$validExitCodes = @(0, 1605, 1614, 1641, 3010)
if ($validExitCodes -contains $exitCode) {
  Exit 0
}

Exit $exitCode

- name: Install bca-docker
  win_chocolatey:
    name: bca-docker
    version: '0.3.0'
    source: INTERNAL REPO URL
    state: present

See docs at https://docs.ansible.com/ansible/latest/modules/win_chocolatey_module.html.


chocolatey_package 'bca-docker' do
  action    :install
  source   'INTERNAL REPO URL'
  version  '0.3.0'
end

See docs at https://docs.chef.io/resource_chocolatey_package.html.


cChocoPackageInstaller bca-docker
{
    Name     = "bca-docker"
    Version  = "0.3.0"
    Source   = "INTERNAL REPO URL"
}

Requires cChoco DSC Resource. See docs at https://github.com/chocolatey/cChoco.


package { 'bca-docker':
  ensure   => '0.3.0',
  provider => 'chocolatey',
  source   => 'INTERNAL REPO URL',
}

Requires Puppet Chocolatey Provider module. See docs at https://forge.puppet.com/puppetlabs/chocolatey.


4. If applicable - Chocolatey configuration/installation

See infrastructure management matrix for Chocolatey configuration elements and examples.

Package Approved

This package was approved by moderator flcdrg on 21 Dec 2024.

Description

PowerShell module to manage Docker containers.


tools\Bca.Docker\Bca.Docker.psd1
#
# Module manifest for module 'Bca.Docker'
#
# Generated by: Baptiste Cabrera
#
# Generated on: 10/14/2020
#

@{

# Script module or binary module file associated with this manifest.
RootModule = 'Bca.Docker'

# Version number of this module.
ModuleVersion = '0.3.0'

# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
GUID = '0a3e7866-6d7a-4cf4-9b43-636792078631'

# Author of this module
Author = 'Baptiste Cabrera'

# Company or vendor of this module
CompanyName = 'Bca'

# Copyright statement for this module
Copyright = '(c) 2020 Bca. All rights reserved.'

# Description of the functionality provided by this module
Description = 'PowerShell module to manage Docker containers.'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.1'

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# CLRVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Get-DockerContainer', 'Invoke-DockerContainerCommand', 
               'Start-DockerContainer', 'Stop-DockerContainer'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Variables to export from this module
# VariablesToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

    #projectSourceUrl of this module
    projectSourceUrl = 'https://github.com/baptistecabrera/bca-docker/tree/master/src'

    #docsUrl of this module
    docsUrl = 'https://github.com/baptistecabrera/bca-docker/tree/master/doc'

    #repositoryUrl of this module
    repositoryUrl = 'https://github.com/baptistecabrera/bca-docker.git'

    #License of this module
    License = 'MIT'

    #packageSourceUrl of this module
    packageSourceUrl = 'https://github.com/baptistecabrera/bca-docker/tree/master/src'

    #bugTrackerUrl of this module
    bugTrackerUrl = 'https://github.com/baptistecabrera/bca-docker/issues'

    #mailingListUrl of this module
    mailingListUrl = 'https://github.com/baptistecabrera/bca-docker/issues'

    PSData = @{

        # Tags applied to this module. These help with module discovery in online galleries.
        Tags = 'docker','container','Windows','Linux','MacOS'

        # A URL to the license for this module.
        LicenseUri = 'https://github.com/baptistecabrera/bca-docker/blob/master/LICENSE'

        # A URL to the main website for this project.
        ProjectUri = 'https://github.com/baptistecabrera/bca-docker'

        # A URL to an icon representing this module.
        IconUri = 'https://www.powershellgallery.com/Content/Images/Branding/packageDefaultIcon.png'

        # ReleaseNotes of this module
        ReleaseNotes = '0.3.0:
- Invoke-DockerContainerCommand:
  - Added support for ArgumentList parameter;
  - Added AuthenticationOn parameter that allows to specify whether to use Credential and Authentication paramaters on the host, container or both.

0.2.0:
- Added ShouldProcess support on some functions;
- Added support for Authentication and Credential parameters.

0.1.0:
- Get-DockerContainer: function to retrieve docker informations;
- Invoke-DockerContainerCommand: function to execute a command, script or script block in a docker container;
- Start-DockerContainer/Stop-DockerConatainer: functions to start or stop a docke container;
- Supports Windows, Linux and MacOS;
- Supports English and French language.'

        # Prerelease string of this module
        # Prerelease = ''

        # Flag to indicate whether the module requires explicit user acceptance for install/update/save
        # RequireLicenseAcceptance = $false

        # External dependent modules of this module
        # ExternalModuleDependencies = @()

    } # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}

tools\Bca.Docker\Bca.Docker.psm1
try
{
    # Importing Localized Data if present (fallback to en-US)
    if (Test-Path (Join-Path $PSScriptRoot LocalizedData))
    {
        $script:LocalizedData = Import-LocalizedData -BaseDirectory (Join-Path $PSScriptRoot LocalizedData) -ErrorAction SilentlyContinue
        if (!$?) { $script:LocalizedData = Import-LocalizedData -UICulture en-US -BaseDirectory (Join-Path $PSScriptRoot LocalizedData) }
    }

    # Gets public and private function definition files.
    $Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Recurse -ErrorAction SilentlyContinue )
    $Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -Recurse -ErrorAction SilentlyContinue )

    # Dot source the files
    foreach ($File in @($Public + $Private))
    {
        try
        {
            . $File.FullName
        }
        catch
        {
            Write-Error -Message ($script:LocalizedData.ImportModule.Error.ImportError.Message -f $File.BaseName, $_) -Category OperationStopped -CategoryActivity $MyInvocation.MyCommand -TargetName $File.BaseName -TargetType $script:LocalizedData.ImportModule.Error.ImportError.Target -Exception OperationStoppedException
        }
    }

    # Exports public functions and their aliases
    Export-ModuleMember -Function $Public.BaseName -Alias *
}
catch 
{
    Write-Error $_
}
tools\Bca.Docker\Bca.Docker.Tests.ps1
if (Test-Path (Join-Path $PSScriptRoot LocalizedData))
{
    $global:TestLocalizedData = Import-LocalizedData -BaseDirectory (Join-Path $PSScriptRoot LocalizedData) -ErrorAction SilentlyContinue
    if (!$?) { $global:TestLocalizedData = Import-LocalizedData -UICulture en-US -BaseDirectory (Join-Path $PSScriptRoot LocalizedData) }
}

Describe $global:TestLocalizedData.Module.Describe {
    BeforeAll {
        $ParentDirectory = Split-Path $PSScriptRoot -Parent
        $Directory = Split-Path $PSScriptRoot -Leaf

        if ([version]::TryParse($Directory, [ref]$null)) { $ModuleName = Split-Path $ParentDirectory -Leaf }
        else { $ModuleName = $Directory }
    }

    It $global:TestLocalizedData.Module.ImportModule {
        try
        {
            Import-Module (Join-Path $PSScriptRoot ("{0}.psd1" -f $ModuleName)) -Force
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }
    
    It $global:TestLocalizedData.Module.CommandCheck {
        $Commands = Get-Command -Module $ModuleName
        $Commands.Count | Should -BeGreaterThan 0
    }
}

Describe $global:TestLocalizedData.StopDocker.Describe {
    BeforeAll {
        $Credential = New-Object -TypeName System.Management.Automation.PSCredential ("User", (ConvertTo-SecureString "P4ssW0rd!" -AsPlainText -Force))

        $Server = "MyHost"
        $Servers = @("MyHost", "MyOtherHost")
        $Name = "MyContainer"
        $Names = @("MyContainer", "MyOtherCOntainer")
        $Id = "123456"
        $Ids = @("123456", "789012")
        $FullId = -join ((0x30..0x39) + ( 0x41..0x5A) + ( 0x61..0x7A) | Get-Random -Count 64  | % { [char]$_ })
        $FullIds = @(( -join ((0x30..0x39) + ( 0x41..0x5A) + ( 0x61..0x7A) | Get-Random -Count 64  | % { [char]$_ })), ( -join ((0x30..0x39) + ( 0x41..0x5A) + ( 0x61..0x7A) | Get-Random -Count 64  | % { [char]$_ })))
        $Container = New-Object -TypeName PSCustomObject @{
            FullId       = $FullId;
            Name         = $Name
            ComputerName = $Server
        }
        $Containers = @()
        $i = 0
        $FullIds | ForEach-Object {
            $CurrentContainer = New-Object -TypeName PSCustomObject @{
                FullId       = $_;
                Name         = $Names[$i]
                ComputerName = $Server
            }
            $Containers += $CurrentContainer
            $i++
        }
    }

    It $global:TestLocalizedData.StopDocker.FromName {
        try
        {
            Stop-DockerContainer -Name $Name -ComputerName $Server -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.StopDocker.FromName {
        try
        {
            Stop-DockerContainer -Name $Names -ComputerName $Servers -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.StopDocker.FromId {
        try
        {
            Stop-DockerContainer -Id $Id -ComputerName $Server -Credential $Credential -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.StopDocker.FromId {
        try
        {
            Stop-DockerContainer -Id $Ids -ComputerName $Servers -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.StopDocker.FromContainer {
        try
        {
            Stop-DockerContainer -Container $Container -Credential $Credential -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.StopDocker.FromContainer {
        try
        {
            $Containers | Stop-DockerContainer -Credential $Credential -Authentication "Default" -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }
}

Describe $global:TestLocalizedData.StartDocker.Describe {
    BeforeAll {
        $CharReference = "abcdefghijklmnopqrstuvwxyz0123456789".ToCharArray() + "abcdefghijklmnopqrstuvwxyz0123456789".ToCharArray()

        $Credential = New-Object -TypeName System.Management.Automation.PSCredential ("User", (ConvertTo-SecureString "P4ssW0rd!" -AsPlainText -Force))
        $Server = "MyHost"
        $Servers = @("MyHost", "MyOtherHost")
        $Name = "MyContainer"
        $Names = @("MyContainer", "MyOtherCOntainer")
        $Id = "123456"
        $Ids = @("123456", "789012")
        $FullId = ($CharReference | Get-Random -Count 64) -join ''
        $FullIds = @((($CharReference | Get-Random -Count 64) -join ''), (($CharReference | Get-Random -Count 64) -join ''))
        $Container = New-Object -TypeName PSCustomObject @{
            FullId       = $FullId;
            Name         = $Name
            ComputerName = $Server
        }
        $Containers = @()
        $i = 0
        $FullIds | ForEach-Object {
            $CurrentContainer = New-Object -TypeName PSCustomObject @{
                FullId       = $_;
                Name         = $Names[$i]
                ComputerName = $Server
            }
            $Containers += $CurrentContainer
            $i++
        }
    }

    It $global:TestLocalizedData.StartDocker.FromName {
        try
        {
            Start-DockerContainer -Name $Name -ComputerName $Server -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.StartDocker.FromName {
        try
        {
            Start-DockerContainer -Name $Names -ComputerName $Servers -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.StartDocker.FromId {
        try
        {
            Start-DockerContainer -Id $Id -ComputerName $Server -Credential $Credential -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.StartDocker.FromId {
        try
        {
            Start-DockerContainer -Id $Ids -ComputerName $Servers -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.StartDocker.FromContainer {
        try
        {
            Start-DockerContainer -Container $Container -Credential $Credential -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.StartDocker.FromContainer {
        try
        {
            $Containers | Start-DockerContainer -Credential $Credential -Authentication "Default" -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }
}

Describe $global:TestLocalizedData.InvokeCommand.Describe {
    BeforeAll {
        $CharReference = "abcdefghijklmnopqrstuvwxyz0123456789".ToCharArray() + "abcdefghijklmnopqrstuvwxyz0123456789".ToCharArray()

        $Credential = New-Object -TypeName System.Management.Automation.PSCredential ("User", (ConvertTo-SecureString "P4ssW0rd!" -AsPlainText -Force))
        $Server = "MyHost"
        $Servers = @("MyHost", "MyOtherHost")
        $Name = "MyContainer"
        $Names = @("MyContainer", "MyOtherCOntainer")
        $Id = "123456"
        $Ids = @("123456", "789012")
        $FullId = ($CharReference | Get-Random -Count 64) -join ''
        $FullIds = @((($CharReference | Get-Random -Count 64) -join ''), (($CharReference | Get-Random -Count 64) -join ''))
        $Container = New-Object -TypeName PSCustomObject @{
            FullId       = $FullId;
            Name         = $Name
            ComputerName = $Server
        }
        $Containers = @()
        $i = 0
        $FullIds | ForEach-Object {
            $CurrentContainer = New-Object -TypeName PSCustomObject @{
                FullId       = $_;
                Name         = $Names[$i]
                ComputerName = $Server
            }
            $Containers += $CurrentContainer
            $i++
        }

        $ScriptPath = Join-Path ([System.IO.Path]::GetTempPath()) "Test.ps1"
        "Write-Host 'Test" | Set-Content $ScriptPath -Force
    }

    It $global:TestLocalizedData.InvokeCommand.FromContainerCommand {
        try
        {
            Invoke-DockerContainerCommand -Container $Container -Command "Write-Host 'Test'" -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.InvokeCommand.FromContainerScriptBlock {
        try
        {
            $Containers | Invoke-DockerContainerCommand -ScriptBlock { Write-Host 'Test' } -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.InvokeCommand.FromIdExpression {
        try
        {
            Invoke-DockerContainerCommand -ContainerId $FullId -ComputerName $Server -Expression "Write-Host 'Test'" -Credential $Credential -AuthenticationOn Host -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.InvokeCommand.FromIdScript {
        try
        {
            Invoke-DockerContainerCommand -ContainerId $FullId -ComputerName $Server -FilePath $ScriptPath -Credential $Credential -Authentication "Default" -AuthenticationOn Container -WhatIf
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $true
    }

    It $global:TestLocalizedData.InvokeCommand.FromIdExpression {
        try
        {
            Invoke-DockerContainerCommand -ContainerId $Id -ComputerName $Server -Expression "Write-Host 'Test'" -Credential $Credential -AuthenticationOn Host, Container -WhatIf -ErrorAction Stop
            $Result = $true
        }
        catch { $Result = $false }
        $Result | Should -Be $false
    }

}
tools\Bca.Docker\LocalizedData\en\Bca.Docker.psd1
@{
    Global                      = @{
        Debug = @{
            Entering = "Entering '{0}'"
            Leaving  = "Leaving '{0}'"
        }
    }

    ImportModule                = @{
        Error = @{
            ImportError = @{
                Message = "Failed to import function '{0}': {1}"
                Target  = "Function"
            }
        }
    }
}
tools\Bca.Docker\LocalizedData\en\Bca.Docker.Tests.psd1
@{
    Module        = @{
        Describe     = "Module"
        ImportModule = "Importing module locally."
        CommandCheck = "Checking exported commands count."
    }

    StopDocker    = @{
        Describe      = "Stop-DockerContainer"
        FromName      = "Stopping container from name"
        FromId        = "Stopping container from ID"
        FromContainer = "Stopping container from container"
    }

    StartDocker   = @{
        Describe      = "Start-DockerContainer"
        FromName      = "Starting container from name"
        FromId        = "Starting container from ID"
        FromContainer = "Starting container from container"
    }

    InvokeCommand = @{
        Describe                 = "Invoke-DockerContainerCommand"
        FromContainerCommand     = "Invoking command in container from container"
        FromContainerScriptBlock = "Invoking script block in container from container"
        FromIdExpression         = "Invoking expression in container from ID"
        FromIdScript             = "Invoking script in container from ID"
    }
}
tools\Bca.Docker\LocalizedData\fr\Bca.Docker.psd1
@{
    Global       = @{
        Debug = @{
            Entering = "Début de la fonction « {0} »"
            Leaving  = "Fin de la fonction « {0} »"
        }
    }

    ImportModule = @{
        Error = @{
            ImportError = @{
                Message = "Impossible d'importer la fonction « {0} »  : {1}"
                Target  = "Fonction"
            }
        }
    }
}
tools\Bca.Docker\LocalizedData\fr\Bca.Docker.Tests.psd1
@{
    Module  = @{
        Describe     = "Module"
        ImportModule = "Importation locale du module."
        CommandCheck = "Vérification du nombre de fonctions exportées."
    }

    StopDocker    = @{
        Describe      = "Stop-DockerContainer"
        FromName      = "Arrêt du conteneur depuis le nom"
        FromId        = "Arrêt du conteneur depuis l'ID"
        FromContainer = "Arrêt du conteneur depuis l'objet"
    }

    StartDocker   = @{
        Describe      = "Start-DockerContainer"
        FromName      = "Démarrage du conteneur depuis le nom"
        FromId        = "Démarrage du conteneur depuis l'ID"
        FromContainer = "Démarrage du conteneur depuis l'objet"
    }

    InvokeCommand = @{
        Describe                 = "Invoke-DockerContainerCommand"
        FromContainerCommand     = "Execution de commande dans le conteneur depuis l'objet"
        FromContainerScriptBlock = "Execution de script block dans le conteneur depuis l'objet"
        FromIdExpression         = "Execution d'expression dans le conteneur depuis l'ID"
        FromIdScript             = "Execution de script dans le conteneur depuis l'ID"
    }
}
tools\Bca.Docker\Private\Control-DockerContainer.ps1
function Control-DockerContainer
{
    <#
        .SYNOPSIS
            Controls a Docker container.
        .DESCRIPTION
            Controls a Docker container.
        .PARAMETER Name
            An array of strings containing the name(s) of the container(s) to control.
            This parameter accepts wildcard character ('*').
        .PARAMETER Id
            An array of strings containing the id(s) of the container(s) to control.
            This can be the shorten or full id.
            This parameter accepts wildcard character ('*').
        .PARAMETER Container
            An array of pscustomobjects containing the containers to control.
        .PARAMETER ComputerName
            An array of string containing the computer(s) where the containers are hosted.
        .PARAMETER Action
            A string containing the action to perform on the conatiner(s).
        .PARAMETER Credential
            A PSCredential used to connect to the host.
        .PARAMETER Authentication
            An AuthenticationMechanism that will be used to authenticate the user's credentials
        .PARAMETER Force
            A switch specifying whether or not to force the action.
        .INPUTS
            System.Management.Automation.PSCustomObject
            You can pipe a value for the containers to this cmdlet.
        .OUTPUTS
            System.Management.Automation.PSCustomObject
            Returns a PSCustomObject containing the containers.
        .EXAMPLE
            Control-DockerContainer -Name MyDocker -ComputerName MyHostServer -Action Start

            Description
            -----------
            This example will start the container named 'MyDocker' on computer 'MyHostServer'.
        .EXAMPLE
            Get-DockerContainer | Control-DockerContainer -Action Stop

            Description
            -----------
            This example will stop all containers hosted on the current computer.
        .NOTES
            If the Container parameter is used, and the status in the object already corresponds to the desired one, no action would be taken unless Force parameter is used.
        .LINK
            Start-DockerContainer
        .LINK
            Stop-DockerContainer
    #>
    [CmdLetBinding(DefaultParameterSetName = "FromName")]
    param(
        [Parameter(ParameterSetName = "FromContainer", Mandatory = $true, ValueFromPipeline = $true)]
        [pscustomobject[]] $Container,
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [string[]] $ComputerName = $env:COMPUTERNAME,
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [string[]] $Name = "",
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [string[]] $Id = "",
        [Parameter(ParameterSetName = "FromContainer", Mandatory = $true)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $true)]
        [Parameter(ParameterSetName = "FromName", Mandatory = $true)]
        [ValidateSet("Stop", "Start")]
        [string] $Action,
        [Parameter(ParameterSetName = "FromContainer", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [pscredential] $Credential,
        [Parameter(ParameterSetName = "FromContainer", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [ValidateSet("Basic", "Default", "Credssp", "Digest", "Kerberos", "Negotiate", "NegotiateWithImplicitCredential")]
        [System.Management.Automation.Runspaces.AuthenticationMechanism] $Authentication = "Default",
        [Parameter(ParameterSetName = "FromContainer", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [switch] $Force
    )

    begin
    {
        Write-Debug ($script:LocalizedData.Global.Debug.Entering -f $PSCmdlet.MyInvocation.MyCommand)
        if ($PSCmdlet.ParameterSetName -ne "FromContainer")
        {
            $Params = $PSBoundParameters
            $Params.Remove("Action") | Out-Null
            $Params.Remove("Force") | Out-Null
            $Container = Get-DockerContainer @Params
        }
        $Action = $Action.ToLower()
        if (!$Force)
        {
            $RequiredStatus = switch ($Action) {
                "stop" { "Exited" }
                "start" { "Up" }
            }
        }
    }
    process
    {
        $Container.ComputerName | Sort-Object -Unique | ForEach-Object {
            try 
            {
                $CurrentComputerName = $_
                # $Container | Where-Object { ($_.ComputerName -eq $CurrentComputerName) -and ($_.Status -eq $RequiredStatus) }
                $FilteredContainer = $Container | Where-Object { ($_.ComputerName -eq $CurrentComputerName) -and ($_.Status -ne $RequiredStatus) }
                if ($FilteredContainer)
                {
                    $Parameters = @{
                        ComputerName = $CurrentComputerName
                    }
                    if ($PSBoundParameters.Credential) { $Parameters.Add("Credential", $Credential) }
                    if ($PSBoundParameters.Authentication) { $Parameters.Add("Authentication", $Authentication) }
                    $Control = Invoke-Command @Parameters -ScriptBlock { Invoke-Expression "docker $($using:Action) $($using:FilteredContainer.Id -join ' ')" }
                    Get-DockerContainer -Id $FilteredContainer.Id -ComputerName $CurrentComputerName
                }
            }
            catch
            {
                Write-Error $_
            }
        }
    }
    end
    {
        Write-Debug ($script:LocalizedData.Global.Debug.Leaving -f $PSCmdlet.MyInvocation.MyCommand)
    }
}
tools\Bca.Docker\Public\Get-DockerContainer.ps1
function Get-DockerContainer
{
    <#
        .SYNOPSIS
            Gets a Docker container.
        .DESCRIPTION
            Gets a Docker container.
        .PARAMETER Name
            An array of strings containing the name(s) of the container(s) to get.
            This parameter accepts wildcard character ('*').
        .PARAMETER Id
            An array of strings containing the id(s) of the container(s) to get.
            This can be the shorten or full id.
            This parameter accepts wildcard character ('*').
        .PARAMETER ComputerName
            Am array of string containing the computer(s) where the containers are hosted.
        .PARAMETER IncludeExtendedProperties
            A switch specifying whether or not to retrieve extended properties.
        .PARAMETER Credential
            A PSCredential used to connect to the host.
        .PARAMETER Authentication
            An AuthenticationMechanism that will be used to authenticate the user's credentials
        .OUTPUTS
            System.Management.Automation.PSCustomObject
            Returns a PSCustomObject containing the containers.
        .EXAMPLE
            Get-DockerContainer -Name MyDocker* -ComputerName MyHostServer01, MyHostServer02

            Description
            -----------
            This example will get the containers whose name match 'MyDocker*' on computers 'MyHostServer01' and 'MyHostServer02'.
        .EXAMPLE
            Get-DockerContainer -Id 97590b5306b9, 4f657b6d8066b87455303c591873b0739aa14f589cd56365a46a256f726c6be0 -ComputerName MyHostServer

            Description
            -----------
            This example will get the containers with IDs '97590b5306b9' and '4f657b6d8066b87455303c591873b0739aa14f589cd56365a46a256f726c6be0' on computer 'MyHostServer'.
        .NOTES
            Extended properties correspond to a docker container inspect command.
    #>
    [CmdLetBinding(DefaultParameterSetName = "FromName")]
    param(
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Alias("Cn")]
        [string[]] $ComputerName = $env:COMPUTERNAME,
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [string[]] $Name = "",
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [string[]] $Id = "",
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [switch] $IncludeExtendedProperties,
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [pscredential] $Credential,
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [ValidateSet("Basic", "Default", "Credssp", "Digest", "Kerberos", "Negotiate", "NegotiateWithImplicitCredential")]
        [System.Management.Automation.Runspaces.AuthenticationMechanism] $Authentication = "Default"
    )

    Write-Debug ($script:LocalizedData.Global.Debug.Entering -f $PSCmdlet.MyInvocation.MyCommand)
    try 
    {
        $ComputerName | ForEach-Object { 
            $CurrentComputerName = $_
            $Parameters = @{
                ComputerName = $CurrentComputerName
            }
            if ($PSBoundParameters.Credential) { $Parameters.Add("Credential", $Credential) }
            if ($PSBoundParameters.Authentication) { $Parameters.Add("Authentication", $Authentication) }
            Invoke-Command @Parameters -ScriptBlock { Invoke-Expression "docker ps -a --no-trunc" } | Where-Object { ($_ -notlike "CONTAINER ID*") } | ForEach-Object {
                $CurrentContainer = New-Object -TypeName PsObject
                $ContainerProperties = $_ -split "  " | Where-Object { $_ } | ForEach-Object {
                    if ($_.StartsWith(" ")) { $_ = $_.SubString(1) }
                    $_
                }
                $CurrentContainer | Add-Member -MemberType NoteProperty -Name Id -Value $ContainerProperties[0].SubString(0, 12) -PassThru | Out-Null
                $CurrentContainer | Add-Member -MemberType NoteProperty -Name FullId -Value $ContainerProperties[0] -PassThru | Out-Null
                $CurrentContainer | Add-Member -MemberType NoteProperty -Name Name -Value $ContainerProperties[$ContainerProperties.Count - 1] -PassThru | Out-Null
                $CurrentContainer | Add-Member -MemberType NoteProperty -Name Command -Value ($ContainerProperties | Where-Object { $_ -like """*""" }) -PassThru | Out-Null
                $CommandIndex = [array]::IndexOf($ContainerProperties, $CurrentContainer.Command)
                if ($ContainerProperties[$CommandIndex - 1] -ne $CurrentContainer.LongId) { $CurrentContainer | Add-Member -MemberType NoteProperty -Name Image -Value $ContainerProperties[$CommandIndex -1] -PassThru | Out-Null }
                $CurrentContainer | Add-Member -MemberType NoteProperty -Name Created -Value $ContainerProperties[$CommandIndex + 1] -PassThru | Out-Null
                $CurrentContainer | Add-Member -MemberType NoteProperty -Name Status -Value $ContainerProperties[$CommandIndex + 2].Split(" ")[0] -PassThru | Out-Null
                $CurrentContainer | Add-Member -MemberType NoteProperty -Name FullStatus -Value $ContainerProperties[$CommandIndex + 2] -PassThru | Out-Null
                if ($ContainerProperties[$CommandIndex + 3] -ne $CurrentContainer.Name) { $Port = $ContainerProperties[$CommandIndex + 3] }
                $CurrentContainer | Add-Member -MemberType NoteProperty -Name Port -Value $Port -PassThru | Out-Null
                $CurrentContainer | Add-Member -MemberType NoteProperty -Name ComputerName -Value $CurrentComputerName -PassThru | Out-Null
                if ((!$Name -and !$Id) -or ($Name -and (($CurrentContainer.Name -in $Name) -or ($CurrentContainer.Name -like $Name))) -or ($Id -and (($CurrentContainer.Id -in $Id) -or ($CurrentContainer.FullId -in $Id) -or ($CurrentContainer.Id -like $Id) -or ($CurrentContainer.FullId -like $Id)))) 
                {
                    if ($IncludeExtendedProperties)
                    {
                        $ExtendedProperties = Invoke-Command @Parameters -ScriptBlock {
                            param([string] $ContainerId)
                            Invoke-Expression "docker inspect $ContainerId"
                        } -ArgumentList $CurrentContainer.Id 
                        $ExtendedProperties = $ExtendedProperties | ConvertFrom-Json
                        if ($ExtendedProperties.Created) { $ExtendedProperties | Add-Member -MemberType NoteProperty -Name Created -Value (Get-Date $ExtendedProperties.Created) -PassThru -Force | Out-Null }
                        if ($ExtendedProperties.State.StartedAt) { $ExtendedProperties.State | Add-Member -MemberType NoteProperty -Name StartedAt -Value (Get-Date $ExtendedProperties.State.StartedAt) -PassThru -Force | Out-Null }
                        if ($ExtendedProperties.State.FinishedAt) { $ExtendedProperties.State | Add-Member -MemberType NoteProperty -Name FinishedAt -Value (Get-Date $ExtendedProperties.State.FinishedAt) -PassThru -Force | Out-Null }
                        if ($ExtendedProperties.Config.Labels.'com.docker.compose.version') { $ExtendedProperties.Config.Labels | Add-Member -MemberType NoteProperty -Name 'com.docker.compose.version' -Value ([version]($ExtendedProperties.Config.Labels.'com.docker.compose.version')) -PassThru -Force | Out-Null }
                        $CurrentContainer | Add-Member -MemberType NoteProperty -Name ExtendedProperties -Value $ExtendedProperties  -PassThru | Out-Null
                    }
                    $CurrentContainer
                }
            }
        }
    }
    catch
    {
        Write-Error $_
    }
    finally
    {
        Write-Debug ($script:LocalizedData.Global.Debug.Leaving -f $PSCmdlet.MyInvocation.MyCommand)
    }
}
tools\Bca.Docker\Public\Invoke-DockerContainerCommand.ps1
function Invoke-DockerContainerCommand
{
    <#
        .SYNOPSIS
            Invokes a command inside a Docker container.
        .DESCRIPTION
            Invokes a command inside a Docker container.
        .PARAMETER ContainerId
            An array of strings containing the full id(s) (64 characters) of the container(s) where the command will be run.
        .PARAMETER Container
            An array of pscustomobjects containing the container(s) where the command will be run.
        .PARAMETER ComputerName
            An array of string containing the computer(s) where the containers are hosted.
        .PARAMETER Command
            An array of string containing the command(s) to run in the container.
        .PARAMETER Expression
            A string containing the expression to run in the container.
        .PARAMETER ScriptBlock
            An script block describing the command(s) to run in the container.
        .PARAMETER FilePath
            A string containing the path of a local powershell script to run in the container.
        .PARAMETER ArgumentList
            An array of object specifying the arguments - local variables or values - to pass to the command, script or script block.
            The param keyword lists the local variables that are used in the command. ArgumentList supplies the values of the variables, in the order that they're listed.
        .PARAMETER RunAsAdministrator
            A switch sepcifying wheter or not this cmdlet invokes a command as an Administrator.
        .PARAMETER AsJob
            A switch specifying whether or not to run the command as a background job in the container.
        .PARAMETER JobName
            A string the name of the job if the command is run as a background job in the container. By default, jobs are named Job<n>, where <n> is an ordinal number.
            If you use the JobName parameter in a command, the command is run as a job, and Invoke-DockerContainerCommand returns a job object, even if you do not include AsJob in the command.
        .PARAMETER Credential
            A PSCredential used to connect to the host.
        .PARAMETER Authentication
            An AuthenticationMechanism that will be used to authenticate the user's credentials.
        .PARAMETER AuthenticationOn
            An array of string specifying whether to use Credential and Authentication on the host, the container or both.
        .PARAMETER Force
            A switch specifying whether or not to force the action.
        .INPUTS
            System.Management.Automation.PSCustomObject
            You can pipe a value for the containers to this cmdlet.
        .OUTPUTS
            System.Management.Automation.PSRemotingJob, or the output of the invoked command
            This cmdlet returns a job object, if you use the AsJob parameter. Otherwise, it returns the output of the invoked command, which is the value of the ScriptBlock parameter.
        .EXAMPLE
            Invoke-DockerContainerCommand -Command "Get-Service -Name MyService" -ContainerId 4f657b6d8066b87455303c591873b0739aa14f589cd56365a46a256f726c6be0 -ComputerName MyHostServer

            Description
            -----------
            This example will get the service MyService in the container with id '4f657b6d8066b87455303c591873b0739aa14f589cd56365a46a256f726c6be0' on computer 'MyHostServer'.
        .EXAMPLE
            Get-DockerContainer | Invoke-DockerContainerCommand -ScriptBlock {
                param([string] $ServiceName)

                Get-Service -Name $ServiceName | Stop-Service
                [...]
                Get-Service -Name $ServiceName | Start-Service
            } -ArgumentList "MyService"

            Description
            -----------
            This example will get all containers hosted on the current computer, stop the service MyService, do some processing and start the service on each of them.
        .EXAMPLE
            Get-ChildItem
                Directory: C:\Script

            Mode                LastWriteTime         Length Name
            ----                -------------         ------ ----
            -a----       2020-09-02   8:56 AM           4579 BackEndScript.ps1
            -a----       2020-09-02  11:25 AM           5979 FrontEndScript.ps1

            Get-DockerContainer -Name "*BackEnd" -ComputerName MyHostServer -Credential DOMAIN\MyUser -Authentication CredSSP | Invoke-DockerContainerCommand -FilePath C:\Scripts\BackEndScript.ps1 -ArgumentList $Arg0, $Arg1 -RunAsAdministrator -RunAsJob -Credential DOMAIN\MyUser -Authentication CredSSP -AuthenticationOn Host, Docker

            Description
            -----------
            This example will get all containers that match "*BackEnd" on computer MyHostServer, using DOMAIN\MyUser with CredSSP on both the host server and the container, and run the script C:\Scripts\BackEndScript.ps1 as administrator and as a job in each container.
        .NOTES
        .LINK
            Invoke-Command
    #>
    [CmdLetBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
    param(
        [Parameter(ParameterSetName = "FromContainerObjectAndCommand", Mandatory = $true, ValueFromPipeline = $true)]
        [Parameter(ParameterSetName = "FromContainerObjectAndScriptBlock", Mandatory = $true, ValueFromPipeline = $true)]
        [Parameter(ParameterSetName = "FromContainerObjectAndFilePath", Mandatory = $true, ValueFromPipeline = $true)]
        [Parameter(ParameterSetName = "FromContainerObjectAndExpression", Mandatory = $true, ValueFromPipeline = $true)]
        [pscustomobject[]] $Container,
        [Parameter(ParameterSetName = "FromContainerIdAndCommand", Mandatory = $true)]
        [Parameter(ParameterSetName = "FromContainerIdAndScriptBlock", Mandatory = $true)]
        [Parameter(ParameterSetName = "FromContainerIdAndFilePath", Mandatory = $true)]
        [Parameter(ParameterSetName = "FromContainerIdAndExpression", Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [ValidateLength(64, 64)]
        [string] $ContainerId,
        [Parameter(ParameterSetName = "FromContainerIdAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndExpression", Mandatory = $false)]
        [Alias("Cn")]
        [string] $ComputerName = $env:COMPUTERNAME,
        [Parameter(ParameterSetName = "FromContainerObjectAndCommand", Mandatory = $true)]
        [Parameter(ParameterSetName = "FromContainerIdAndCommand", Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string[]] $Command,
        [Parameter(ParameterSetName = "FromContainerObjectAndFilePath", Mandatory = $true)]
        [Parameter(ParameterSetName = "FromContainerIdAndFilePath", Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [ValidateScript( { Test-Path $_ } )]
        [Alias("PSPath")]
        [string] $FilePath,
        [Parameter(ParameterSetName = "FromContainerObjectAndExpression", Mandatory = $true)]
        [Parameter(ParameterSetName = "FromContainerIdAndExpression", Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $Expression,
        [Parameter(ParameterSetName = "FromContainerObjectAndScriptBlock", Mandatory = $true)]
        [Parameter(ParameterSetName = "FromContainerIdAndScriptBlock", Mandatory = $true)]
        [scriptblock] $ScriptBlock,
        [Parameter(ParameterSetName = "FromContainerObjectAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndFilePath", Mandatory = $false)]
        [Alias("Args")]
        [object[]] $ArgumentList,
        [Parameter(ParameterSetName = "FromContainerObjectAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndExpression", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndExpression", Mandatory = $false)]
        [switch] $RunAsAdministrator,
        [Parameter(ParameterSetName = "FromContainerObjectAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndExpression", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndExpression", Mandatory = $false)]
        [switch] $AsJob,
        [Parameter(ParameterSetName = "FromContainerObjectAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndExpression", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndExpression", Mandatory = $false)]
        [string] $JobName,
        [Parameter(ParameterSetName = "FromContainerObjectAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndExpression", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndExpression", Mandatory = $false)]
        [pscredential] $Credential,
        [Parameter(ParameterSetName = "FromContainerObjectAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndExpression", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndExpression", Mandatory = $false)]
        [ValidateSet("Basic", "Default", "Credssp", "Digest", "Kerberos", "Negotiate", "NegotiateWithImplicitCredential")]
        [System.Management.Automation.Runspaces.AuthenticationMechanism] $Authentication = "Default",
        [Parameter(ParameterSetName = "FromContainerObjectAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndExpression", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndExpression", Mandatory = $false)]
        [ValidateSet("Host", "Container")]
        [string[]] $AuthenticationOn = "Host",
        [Parameter(ParameterSetName = "FromContainerObjectAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerObjectAndExpression", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndCommand", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndScriptBlock", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndFilePath", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromContainerIdAndExpression", Mandatory = $false)]
        [switch] $Force
    )

    begin
    {
        Write-Debug ($script:LocalizedData.Global.Debug.Entering -f $PSCmdlet.MyInvocation.MyCommand)
        if ($PSCmdlet.ParameterSetName -match "FromContainerId")
        {
            $Container = New-Object -TypeName PSCustomObject @{
                FullId = $ContainerId;
                ComputerName = $ComputerName
            }
            $PSBoundParameters.Remove("ContainerId") | Out-Null
            if ($PSBoundParameters.ComputerName) { $PSBoundParameters.Remove("ComputerName") | Out-Null }
        }
        if ($PSBoundParameters.Force) { $PSBoundParameters.Remove("Force") | Out-Null }
        if ($PSBoundParameters.AuthenticationOn) { $PSBoundParameters.Remove("AuthenticationOn") | Out-Null }
    }
    process
    {
        $Container | ForEach-Object {
            $CurrentContainer = $_
            try 
            {
                $HostParameters = @{
                    ComputerName = $CurrentContainer.ComputerName
                }
                if ($AuthenticationOn -contains "Host")
                {
                    if ($PSBoundParameters.Credential) { $HostParameters.Add("Credential", $Credential) }
                    if ($PSBoundParameters.Authentication) { $HostParameters.Add("Authentication", $Authentication) }
                }

                $ContainerParameters = $PSBoundParameters
                if ($ContainerParameters.Container) { $ContainerParameters.Remove("Container") | Out-Null }
                $ContainerParameters.ContainerId = $CurrentContainer.FullId
                if ($ContainerParameters.FilePath) { $ContainerParameters.FilePath = Get-Content $ContainerParameters.FilePath }
                if (!($AuthenticationOn -contains "Container"))
                {
                    if ($ContainerParameters.Credential) { $ContainerParameters.Remove("Credential") | Out-Null }
                    if ($ContainerParameters.Authentication) { $ContainerParameters.Remove("Authentication") | Out-Null }
                }
                if ($ContainerParameters.WhatIf) { $ContainerParameters.Remove("WhatIf") | Out-Null }
                if ($ContainerParameters.Confirm) { $ContainerParameters.Remove("Confirm") | Out-Null }
                if ($CurrentContainer.Name) { $Target = $CurrentContainer.Name }
                else { $Target = $CurrentContainer.FullId }

                if ($Force -or $PSCmdlet.ShouldProcess($Target))
                {
                    Invoke-Command @HostParameters -ScriptBlock {
                        try
                        {
                            $ContainerParameters = $using:ContainerParameters
                            if ($ContainerParameters.Expression)
                            {
                                $ContainerParameters.Add("Command", "Invoke-Expression `"$($ContainerParameters.Expression)`"")
                                $ContainerParameters.Remove("Expression") | Out-Null
                            }
                            if ($ContainerParameters.FilePath)
                            {
                                $FilePath = (Join-Path $env:TEMP ("{0}.ps1" -f (New-Guid).ToString()))
                                $ContainerParameters.FilePath | Set-Content $FilePath
                                $ContainerParameters.FilePath = $FilePath
                            }
                            if ($ContainerParameters.Command) { $ContainerParameters.Command = [scriptblock]::Create($ContainerParameters.Command -join ";") }
                            if ($ContainerParameters.ScriptBlock) { $ContainerParameters.ScriptBlock = [scriptblock]::Create($ContainerParameters.ScriptBlock) }

                            Invoke-Command @ContainerParameters     
                        }
                        catch
                        {
                            Write-Error $_
                        }
                        finally 
                        {
                            if ($ContainerParameters.FilePath) { Remove-Item $ContainerParameters.FilePath -Force -ErrorAction SilentlyContinue }
                        }
                    }
                }
            }
            catch 
            {
                Write-Error $_    
            }
        }
    }
    end
    {
        Write-Debug ($script:LocalizedData.Global.Debug.Leaving -f $PSCmdlet.MyInvocation.MyCommand)
    }
}
tools\Bca.Docker\Public\Start-DockerContainer.ps1
function Start-DockerContainer
{
    <#
        .SYNOPSIS
            Starts a Docker container.
        .DESCRIPTION
            Starts a Docker container.
        .PARAMETER Name
            An array of strings containing the name(s) of the container(s) to start.
            This parameter accepts wildcard character ('*').
        .PARAMETER Id
            An array of strings containing the id(s) of the container(s) to start.
            This can be the shorten or full id.
            This parameter accepts wildcard character ('*').
        .PARAMETER Container
            An array of pscustomobjects containing the containers to start.
        .PARAMETER ComputerName
            An array of string containing the computer(s) where the containers are hosted.
        .PARAMETER Credential
            A PSCredential used to connect to the host.
        .PARAMETER Authentication
            An AuthenticationMechanism that will be used to authenticate the user's credentials
        .PARAMETER Force
            A switch specifying whether or not to force the action.
        .INPUTS
            System.Management.Automation.PSCustomObject
            You can pipe a value for the containers to this cmdlet.
        .OUTPUTS
            System.Management.Automation.PSCustomObject
            Returns a PSCustomObject containing the containers.
        .EXAMPLE
            Start-DockerContainer -Name MyDocker -ComputerName MyHostServer

            Description
            -----------
            This example will start the container named 'MyDocker' on computer 'MyHostServer'.
        .EXAMPLE
            Get-DockerContainer | Start-DockerContainer

            Description
            -----------
            This example will start all containers hosted on the current computer.
        .NOTES
            If the Container parameter is used, and the status in the object already corresponds to the desired one, no action would be taken unless Force parameter is used.
        .LINK
            Stop-DockerContainer
    #>
    [CmdLetBinding(DefaultParameterSetName = "FromName", SupportsShouldProcess = $true, ConfirmImpact = 'High')]
    param(
        [Parameter(ParameterSetName = "FromContainer", Mandatory = $true, ValueFromPipeline = $true)]
        [pscustomobject[]] $Container,
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Alias("Cn")]
        [string[]] $ComputerName = $env:COMPUTERNAME,
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [string[]] $Name = "",
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [string[]] $Id = "",
        [Parameter(ParameterSetName = "FromContainer", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [pscredential] $Credential,
        [Parameter(ParameterSetName = "FromContainer", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [ValidateSet("Basic", "Default", "Credssp", "Digest", "Kerberos", "Negotiate", "NegotiateWithImplicitCredential")]
        [System.Management.Automation.Runspaces.AuthenticationMechanism] $Authentication = "Default",
        [Parameter(ParameterSetName = "FromContainer", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [switch] $Force
    )
    
    begin { Write-Debug ($script:LocalizedData.Global.Debug.Entering -f $PSCmdlet.MyInvocation.MyCommand) }
    process
    {
        switch -Regex ($PSCmdlet.ParameterSetName)
        {
            "FromContainer" { $Target = $Container.Name -join ", " }
            "FromId" { $Target = $Id -join ", " }
            "FromName" { $Target = $Name -join ", " }
        }
        try { if ($Force -or $PSCmdlet.ShouldProcess($Target)) { Control-DockerContainer @PSBoundParameters -Action "Start" } }
        catch { Write-Error $_ }
    }
    end { Write-Debug ($script:LocalizedData.Global.Debug.Leaving -f $PSCmdlet.MyInvocation.MyCommand) }
}
tools\Bca.Docker\Public\Stop-DockerContainer.ps1
function Stop-DockerContainer
{
    <#
        .SYNOPSIS
            Stops a Docker container.
        .DESCRIPTION
            Stops a Docker container.
        .PARAMETER Name
            An array of strings containing the name(s) of the container(s) to stop.
            This parameter accepts wildcard character ('*').
        .PARAMETER Id
            An array of strings containing the id(s) of the container(s) to stop.
            This can be the shorten or full id.
            This parameter accepts wildcard character ('*').
        .PARAMETER Container
            An array of pscustomobjects containing the containers to stop.
        .PARAMETER ComputerName
            An array of string containing the computer(s) where the containers are hosted.
        .PARAMETER Credential
            A PSCredential used to connect to the host.
        .PARAMETER Authentication
            An AuthenticationMechanism that will be used to authenticate the user's credentials
        .PARAMETER Force
            A switch specifying whether or not to force the action.
        .INPUTS
            System.Management.Automation.PSCustomObject
            You can pipe a value for the containers to this cmdlet.
        .OUTPUTS
            System.Management.Automation.PSCustomObject
            Returns a PSCustomObject containing the containers.
        .EXAMPLE
            Stop-DockerContainer -Name MyDocker -ComputerName MyHostServer

            Description
            -----------
            This example will stop the container named 'MyDocker' on computer 'MyHostServer'.
        .EXAMPLE
            Get-DockerContainer | Stop-DockerContainer

            Description
            -----------
            This example will stop all containers hosted on the current computer.
        .NOTES
            If the Container parameter is used, and the status in the object already corresponds to the desired one, no action would be taken unless Force parameter is used.
        .LINK
            Start-DockerContainer
    #>
    [CmdLetBinding(DefaultParameterSetName = "FromName", SupportsShouldProcess = $true, ConfirmImpact = 'High')]
    param(
        [Parameter(ParameterSetName = "FromContainer", Mandatory = $true, ValueFromPipeline = $true)]
        [pscustomobject[]] $Container,
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Alias("Cn")]
        [string[]] $ComputerName = $env:COMPUTERNAME,
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [string[]] $Name = "",
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [string[]] $Id = "",
        [Parameter(ParameterSetName = "FromContainer", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [pscredential] $Credential,
        [Parameter(ParameterSetName = "FromContainer", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [ValidateSet("Basic", "Default", "Credssp", "Digest", "Kerberos", "Negotiate", "NegotiateWithImplicitCredential")]
        [System.Management.Automation.Runspaces.AuthenticationMechanism] $Authentication = "Default",
        [Parameter(ParameterSetName = "FromContainer", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromId", Mandatory = $false)]
        [Parameter(ParameterSetName = "FromName", Mandatory = $false)]
        [switch] $Force
    )
    
    begin { Write-Debug ($script:LocalizedData.Global.Debug.Entering -f $PSCmdlet.MyInvocation.MyCommand) }
    process
    {
        switch -Regex ($PSCmdlet.ParameterSetName)
        {
            "FromContainer" { $Target = $Container.Name -join ", " }
            "FromId" { $Target = $Id -join ", " }
            "FromName" { $Target = $Name -join ", " }
        }
        try { if ($Force -or $PSCmdlet.ShouldProcess($Target)) { Control-DockerContainer @PSBoundParameters -Action "Stop" } }
        catch { Write-Error $_ }
    }
    end { Write-Debug ($script:LocalizedData.Global.Debug.Leaving -f $PSCmdlet.MyInvocation.MyCommand) }
}
tools\chocolateyInstall.ps1
$ErrorActionPreference = "Stop"

$ModuleName = $env:ChocolateyPackageTitle
$ModuleVersion = $env:ChocolateyPackageVersion
$ModulePath = @()
$PackageParameters = Get-PackageParameters

Remove-Module -Name $ModuleName -Force -ErrorAction SilentlyContinue

if ($PackageParameters.Desktop -or !$PackageParameters.Core)
{
    if ($PSVersionTable.PSVersion -lt [Version]'5.1') { Write-Warning "PowerShell version '$($PSVersionTable.PSVersion.ToString())' is not supported to install this package, at least PowerShell 5.1 must be installed, the module may not work properly." }
    $ModulePath += Join-Path (Join-Path $env:ProgramFiles "WindowsPowerShell\Modules") "$ModuleName\$ModuleVersion"
}
if ($PackageParameters.Core) { $ModulePath += Join-Path (Join-Path $env:ProgramFiles "PowerShell\Modules") "$ModuleName\$ModuleVersion" }

$ModulePath -join "`r`n" | Set-Content (Join-Path $PSScriptRoot "installPath.txt")

$ModulePath | ForEach-Object {
    Write-Verbose "Installation path will be '$_'."

    if ((Test-Path $_))
    {
        Write-Verbose "Removing already installed version."
        Remove-Item -Path $_ -Recurse -Force
    }

    Write-Verbose "Creating folder '$_'."
    New-Item -Path $_ -Force -ItemType Directory | Out-Null

    Write-Verbose "Installing module '$ModuleName' version $ModuleVersion in '$_'."
    Get-ChildItem -Path (Join-Path $PSScriptRoot $ModuleName) | Copy-Item -Destination $_ -Recurse -Container -Force
}

Write-Verbose "Module '$ModuleName' version $ModuleVersion installed."
tools\chocolateyUninstall.ps1
$ErrorActionPreference = "Stop"

$ModuleName = $env:ChocolateyPackageTitle
$ModuleVersion = $env:ChocolateyPackageVersion
$ModulePath = Get-Content (Join-Path $PSScriptRoot "installPath.txt") -ErrorAction SilentlyContinue

Remove-Module -Name $ModuleName -Force -ErrorAction SilentlyContinue

if (!$ModulePath) { Write-Warning "No module path found, '$ModuleName' may have been manually uninstalled." }
$ModulePath | ForEach-Object {
    $ParentModulePath = (Split-Path $_ -Parent)

    Write-Verbose "Module path is '$_'."

    if ((Test-Path $_))
    {
        Write-Verbose "Emtpying directory '$_'."
        Remove-Item -Path $_ -Recurse -Force
    }
    else { Write-Warning "Path '$_' not found, '$ModuleName' may have been manually uninstalled." }
    if ((Test-Path $ParentModulePath) -and ((Get-ChildItem -Path $ParentModulePath | Measure-Object).Count -eq 0))
    {
        Write-Verbose "No file left in '$($ParentModulePath)', removing folder."
        Remove-Item -Path $ParentModulePath -Recurse -Force
    }
}

Write-Verbose "Module '$ModuleName' version $ModuleVersion uninstalled."
tools\LICENSE.txt
MIT License

Copyright (c) 2020 Baptiste Cabrera

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
tools\VERIFICATION.txt
VERIFICATION
Verification is intended to assist the Chocolatey moderators and community in verifying that this package's contents are trustworthy.

1. Download the source from GitHub (use "Software Source" link) or from the PowerShell Gallery;
2. Use Get-FileHash -Path <FILE TO VERIFY> to get the file hash value from both the source file (from step 1 above) and the file from the package and compare them.

Note: PowerShell module manifest file (.psd1) may have been updated during build process, and hash may not match.

Log in or click on link to see number of positives.

In cases where actual malware is found, the packages are subject to removal. Software sometimes has false positives. Moderators do not necessarily validate the safety of the underlying software, only that a package retrieves software from the official distribution point and/or validate embedded software against official distribution point (where distribution rights allow redistribution).

Chocolatey Pro provides runtime protection from possible malware.

Add to Builder Version Downloads Last Updated Status
Bca.Docker 0.2.0 139 Wednesday, September 30, 2020 Approved
Bca.Docker 0.1.0 145 Wednesday, September 23, 2020 Approved

0.3.0:

  • Invoke-DockerContainerCommand:
    • Added support for ArgumentList parameter;
    • Added AuthenticationOn parameter that allows to specify whether to use Credential and Authentication paramaters on the host, container or both.

0.2.0:

  • Added ShouldProcess support on some functions;
  • Added support for Authentication and Credential parameters.

0.1.0:

  • Get-DockerContainer: function to retrieve docker informations;
  • Invoke-DockerContainerCommand: function to execute a command, script or script block in a docker container;
  • Start-DockerContainer/Stop-DockerConatainer: functions to start or stop a docke container;
  • Supports Windows, Linux and MacOS;
  • Supports English and French language.

This package has no dependencies.

Discussion for the Bca.Docker Package

Ground Rules:

  • This discussion is only about Bca.Docker and the Bca.Docker package. If you have feedback for Chocolatey, please contact the Google Group.
  • This discussion will carry over multiple versions. If you have a comment about a particular version, please note that in your comments.
  • The maintainers of this Chocolatey Package will be notified about new comments that are posted to this Disqus thread, however, it is NOT a guarantee that you will get a response. If you do not hear back from the maintainers after posting a message below, please follow up by using the link on the left side of this page or follow this link to contact maintainers. If you still hear nothing back, please follow the package triage process.
  • Tell us what you love about the package or Bca.Docker, or tell us what needs improvement.
  • Share your experiences with the package, or extra configuration or gotchas that you've found.
  • If you use a url, the comment will be flagged for moderation until you've been whitelisted. Disqus moderated comments are approved on a weekly schedule if not sooner. It could take between 1-5 days for your comment to show up.
comments powered by Disqus