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