github.com/guilhermebr/docker@v1.4.2-0.20150428121140-67da055cebca/docs/sources/articles/dsc.md (about)

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