github.com/portworx/docker@v1.12.1/docs/admin/dsc.md (about)

     1  <!--[metadata]>
     2  +++
     3  aliases = ["/engine/articles/dsc/"]
     4  title = "PowerShell DSC Usage"
     5  description = "Using DSC to configure a new Docker host"
     6  keywords = ["powershell, dsc, installation, usage, docker,  documentation"]
     7  [menu.main]
     8  parent = "engine_admin"
     9  weight="10"
    10  +++
    11  <![end-metadata]-->
    12  
    13  # Using PowerShell DSC
    14  
    15  Windows PowerShell Desired State Configuration (DSC) is a configuration
    16  management tool that extends the existing functionality of Windows PowerShell.
    17  DSC uses a declarative syntax to define the state in which a target should be
    18  configured. More information about PowerShell DSC can be found at
    19  [http://technet.microsoft.com/en-us/library/dn249912.aspx](http://technet.microsoft.com/en-us/library/dn249912.aspx).
    20  
    21  ## Requirements
    22  
    23  To use this guide you'll need a Windows host with PowerShell v4.0 or newer.
    24  
    25  The included DSC configuration script also uses the official PPA so
    26  only an Ubuntu target is supported. The Ubuntu target must already have the
    27  required OMI Server and PowerShell DSC for Linux providers installed. More
    28  information can be found at [https://github.com/MSFTOSSMgmt/WPSDSCLinux](https://github.com/MSFTOSSMgmt/WPSDSCLinux).
    29  The source repository listed below also includes PowerShell DSC for Linux
    30  installation and init scripts along with more detailed installation information.
    31  
    32  ## Installation
    33  
    34  The DSC configuration example source is available in the following repository:
    35  [https://github.com/anweiss/DockerClientDSC](https://github.com/anweiss/DockerClientDSC). It can be cloned with:
    36  
    37      $ git clone https://github.com/anweiss/DockerClientDSC.git
    38  
    39  ## Usage
    40  
    41  The DSC configuration utilizes a set of shell scripts to determine whether or
    42  not the specified Docker components are configured on the target node(s). The
    43  source repository also includes a script (`RunDockerClientConfig.ps1`) that can
    44  be used to establish the required CIM session(s) and execute the
    45  `Set-DscConfiguration` cmdlet.
    46  
    47  More detailed usage information can be found at
    48  [https://github.com/anweiss/DockerClientDSC](https://github.com/anweiss/DockerClientDSC).
    49  
    50  ### Install Docker
    51  The Docker installation configuration is equivalent to running:
    52  
    53  ```
    54  apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys\
    55  36A1D7869245C8950F966E92D8576A8BA88D21E9
    56  sh -c "echo deb https://apt.dockerproject.org/repo ubuntu-trusty main\
    57  > /etc/apt/sources.list.d/docker.list"
    58  apt-get update
    59  apt-get install docker-engine
    60  ```
    61  
    62  Ensure that your current working directory is set to the `DockerClientDSC`
    63  source and load the DockerClient configuration into the current PowerShell
    64  session
    65  
    66  ```powershell
    67  . .\DockerClient.ps1
    68  ```
    69  
    70  Generate the required DSC configuration .mof file for the targeted node
    71  
    72  ```powershell
    73  DockerClient -Hostname "myhost"
    74  ```
    75  
    76  A sample DSC configuration data file has also been included and can be modified
    77  and used in conjunction with or in place of the `Hostname` parameter:
    78  
    79  ```powershell
    80  DockerClient -ConfigurationData .\DockerConfigData.psd1
    81  ```
    82  
    83  Start the configuration application process on the targeted node
    84  
    85  ```powershell
    86  .\RunDockerClientConfig.ps1 -Hostname "myhost"
    87  ```
    88  
    89  The `RunDockerClientConfig.ps1` script can also parse a DSC configuration data
    90  file and execute configurations against multiple nodes as such:
    91  
    92  ```powershell
    93  .\RunDockerClientConfig.ps1 -ConfigurationData .\DockerConfigData.psd1
    94  ```
    95  
    96  ### Images
    97  Image configuration is equivalent to running: `docker pull [image]` or
    98  `docker rmi -f [IMAGE]`.
    99  
   100  Using the same steps defined above, execute `DockerClient` with the `Image`
   101  parameter and apply the configuration:
   102  
   103  ```powershell
   104  DockerClient -Hostname "myhost" -Image "node"
   105  .\RunDockerClientConfig.ps1 -Hostname "myhost"
   106  ```
   107  
   108  You can also configure the host to pull multiple images:
   109  
   110  ```powershell
   111  DockerClient -Hostname "myhost" -Image "node","mongo"
   112  .\RunDockerClientConfig.ps1 -Hostname "myhost"
   113  ```
   114  
   115  To remove images, use a hashtable as follows:
   116  
   117  ```powershell
   118  DockerClient -Hostname "myhost" -Image @{Name="node"; Remove=$true}
   119  .\RunDockerClientConfig.ps1 -Hostname $hostname
   120  ```
   121  
   122  ### Containers
   123  Container configuration is equivalent to running:
   124  
   125  ```
   126  docker run -d --name="[containername]" -p '[port]' -e '[env]' --link '[link]'\
   127  '[image]' '[command]'
   128  ```
   129  or
   130  
   131  ```
   132  docker rm -f [containername]
   133  ```
   134  
   135  To create or remove containers, you can use the `Container` parameter with one
   136  or more hashtables. The hashtable(s) passed to this parameter can have the
   137  following properties:
   138  
   139  - Name (required)
   140  - Image (required unless Remove property is set to `$true`)
   141  - Port
   142  - Env
   143  - Link
   144  - Command
   145  - Remove
   146  
   147  For example, create a hashtable with the settings for your container:
   148  
   149  ```powershell
   150  $webContainer = @{Name="web"; Image="anweiss/docker-platynem"; Port="80:80"}
   151  ```
   152  
   153  Then, using the same steps defined above, execute
   154  `DockerClient` with the `-Image` and `-Container` parameters:
   155  
   156  ```powershell
   157  DockerClient -Hostname "myhost" -Image node -Container $webContainer
   158  .\RunDockerClientConfig.ps1 -Hostname "myhost"
   159  ```
   160  
   161  Existing containers can also be removed as follows:
   162  
   163  ```powershell
   164  $containerToRemove = @{Name="web"; Remove=$true}
   165  DockerClient -Hostname "myhost" -Container $containerToRemove
   166  .\RunDockerClientConfig.ps1 -Hostname "myhost"
   167  ```
   168  
   169  Here is a hashtable with all of the properties that can be used to create a
   170  container:
   171  
   172  ```powershell
   173  $containerProps = @{Name="web"; Image="node:latest"; Port="80:80"; `
   174  Env="PORT=80"; Link="db:db"; Command="grunt"}
   175  ```