OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 1 | ===== |
| 2 | Usage |
| 3 | ===== |
Michael Kutý | 1764940 | 2016-03-19 23:57:43 +0100 | [diff] [blame] | 4 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 5 | Docker is a platform for developers and system administrators for developing, |
| 6 | shipping, and running applications. Docker enables you to quickly assemble |
| 7 | applications from components and eliminates the friction that can come when |
| 8 | shipping the code. Also, with Docker, you get your code tested and deployed |
| 9 | into production as fast as possible. |
Michael Kutý | 1764940 | 2016-03-19 23:57:43 +0100 | [diff] [blame] | 10 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 11 | This file provides the sample configurations for different use cases. |
Michael Kutý | 1764940 | 2016-03-19 23:57:43 +0100 | [diff] [blame] | 12 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 13 | Docker host configuration samples |
| 14 | ================================= |
Michael Kutý | 1764940 | 2016-03-19 23:57:43 +0100 | [diff] [blame] | 15 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 16 | * Docker host sample pillar configuration: |
Filip Pytloun | e27a90d | 2016-08-29 14:08:34 +0200 | [diff] [blame] | 17 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 18 | .. code-block:: yaml |
Michael Kutý | 1764940 | 2016-03-19 23:57:43 +0100 | [diff] [blame] | 19 | |
| 20 | docker: |
| 21 | host: |
| 22 | enabled: true |
Tomáš Kukrál | 55cbec7 | 2017-06-19 17:21:04 +0200 | [diff] [blame] | 23 | options: |
| 24 | bip: 172.31.255.1/16 |
Tomáš Kukrál | b2debce | 2017-09-22 08:17:39 +0200 | [diff] [blame] | 25 | insecure-registries: |
Tomáš Kukrál | 55cbec7 | 2017-06-19 17:21:04 +0200 | [diff] [blame] | 26 | - 127.0.0.1 |
| 27 | - 10.0.0.1 |
| 28 | log-driver: json-file |
| 29 | log-opts: |
| 30 | max-size: 50m |
Michael Kutý | 1764940 | 2016-03-19 23:57:43 +0100 | [diff] [blame] | 31 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 32 | * Proxy configuration for Docker host: |
Aleš Komárek | 028b885 | 2017-04-11 13:10:58 +0200 | [diff] [blame] | 33 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 34 | .. code-block:: yaml |
Tomáš Kukrál | 19a3960 | 2017-08-27 22:21:47 +0200 | [diff] [blame] | 35 | |
| 36 | docker: |
| 37 | host: |
| 38 | proxy: |
| 39 | enabled: true |
| 40 | http: http://user:pass@proxy:3128 |
| 41 | https: http://user:pass@proxy:3128 |
| 42 | no_proxy: |
| 43 | - localhost |
| 44 | - 127.0.0.1 |
| 45 | - docker-registry |
| 46 | |
| 47 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 48 | Docker Swarm configuration samples |
| 49 | ================================== |
Filip Pytloun | 2720a0d | 2016-11-02 14:15:55 +0100 | [diff] [blame] | 50 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 51 | Role can be master, manager, or worker. Master is the first manager that |
Filip Pytloun | 2720a0d | 2016-11-02 14:15:55 +0100 | [diff] [blame] | 52 | will initialize the swarm. |
| 53 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 54 | * Metadata for manager (the first node): |
Filip Pytloun | 2720a0d | 2016-11-02 14:15:55 +0100 | [diff] [blame] | 55 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 56 | .. code-block:: yaml |
Filip Pytloun | 2720a0d | 2016-11-02 14:15:55 +0100 | [diff] [blame] | 57 | |
| 58 | docker: |
| 59 | host: |
| 60 | enabled: true |
| 61 | swarm: |
| 62 | role: manager |
| 63 | advertise_addr: 192.168.1.5 |
| 64 | bind: |
| 65 | address: 192.168.1.5 |
| 66 | port: 2377 |
| 67 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 68 | * Metadata for worker: |
Filip Pytloun | 2720a0d | 2016-11-02 14:15:55 +0100 | [diff] [blame] | 69 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 70 | .. code-block:: yaml |
Filip Pytloun | 2720a0d | 2016-11-02 14:15:55 +0100 | [diff] [blame] | 71 | |
| 72 | docker: |
| 73 | host: |
| 74 | enabled: true |
| 75 | swarm: |
| 76 | role: worker |
| 77 | master: |
| 78 | host: 192.168.1.5 |
| 79 | port: 2377 |
| 80 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 81 | The token to join to the master node is obtained from grains using |
| 82 | ``salt.mine``. In case of any ``join_token undefined`` issues, verify that |
| 83 | you have ``docker_swarm_`` grains available. |
Filip Pytloun | 2720a0d | 2016-11-02 14:15:55 +0100 | [diff] [blame] | 84 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 85 | Docker client configuration samples |
| 86 | =================================== |
Michael Kutý | 1764940 | 2016-03-19 23:57:43 +0100 | [diff] [blame] | 87 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 88 | * Container: |
Filip Pytloun | 96fc0cc | 2016-08-29 16:01:10 +0200 | [diff] [blame] | 89 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 90 | .. code-block:: yaml |
Filip Pytloun | 96fc0cc | 2016-08-29 16:01:10 +0200 | [diff] [blame] | 91 | |
Michael Kutý | 1764940 | 2016-03-19 23:57:43 +0100 | [diff] [blame] | 92 | docker: |
Filip Pytloun | e27a90d | 2016-08-29 14:08:34 +0200 | [diff] [blame] | 93 | client: |
Michael Kutý | 1764940 | 2016-03-19 23:57:43 +0100 | [diff] [blame] | 94 | container: |
Filip Pytloun | 8716954 | 2016-08-29 13:38:30 +0200 | [diff] [blame] | 95 | jenkins: |
| 96 | # Don't start automatically |
| 97 | start: false |
| 98 | restart: unless-stopped |
| 99 | image: jenkins:2.7.1 |
Michael Kutý | 1764940 | 2016-03-19 23:57:43 +0100 | [diff] [blame] | 100 | ports: |
Filip Pytloun | 8716954 | 2016-08-29 13:38:30 +0200 | [diff] [blame] | 101 | - 8081:8080 |
| 102 | - 50000:50000 |
| 103 | environment: |
| 104 | JAVA_OPTS: "-Dhudson.footerURL=https://www.example.com" |
| 105 | volumes: |
| 106 | - /srv/volumes/jenkins:/var/jenkins_home |
Michael Kutý | 1764940 | 2016-03-19 23:57:43 +0100 | [diff] [blame] | 107 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 108 | * Docker compose: |
Filip Pytloun | 96fc0cc | 2016-08-29 16:01:10 +0200 | [diff] [blame] | 109 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 110 | The states providing this functionality include: |
Filip Pytloun | a4f6c2f | 2017-04-13 12:00:01 +0200 | [diff] [blame] | 111 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 112 | - docker.client.stack |
| 113 | - docker.client.compose |
Filip Pytloun | a4f6c2f | 2017-04-13 12:00:01 +0200 | [diff] [blame] | 114 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 115 | Stack is new and works with Docker Swarm Mode. |
| 116 | Compose is legacy and works only if node is not a member of Swarm. |
| 117 | Metadata for both states are similar and differs only in implementation. |
Filip Pytloun | a4f6c2f | 2017-04-13 12:00:01 +0200 | [diff] [blame] | 118 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 119 | * Stack: |
Filip Pytloun | a4f6c2f | 2017-04-13 12:00:01 +0200 | [diff] [blame] | 120 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 121 | .. code-block:: yaml |
Filip Pytloun | a4f6c2f | 2017-04-13 12:00:01 +0200 | [diff] [blame] | 122 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 123 | docker: |
| 124 | client: |
| 125 | stack: |
| 126 | django_web: |
| 127 | enabled: true |
| 128 | update: true |
| 129 | environment: |
| 130 | SOMEVAR: somevalue |
| 131 | version: "3.1" |
| 132 | service: |
| 133 | db: |
| 134 | image: postgres |
| 135 | web: |
| 136 | image: djangoapp |
| 137 | volumes: |
| 138 | - /srv/volumes/django:/srv/django |
| 139 | ports: |
| 140 | - 8000:8000 |
| 141 | depends_on: |
| 142 | - db |
Filip Pytloun | a4f6c2f | 2017-04-13 12:00:01 +0200 | [diff] [blame] | 143 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 144 | * Compose |
Filip Pytloun | a4f6c2f | 2017-04-13 12:00:01 +0200 | [diff] [blame] | 145 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 146 | You can install ``docker-compose`` using one of the following options: |
Filip Pytloun | 21d9af9 | 2016-08-30 08:13:39 +0200 | [diff] [blame] | 147 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 148 | - Distribution package (default) |
| 149 | - Using Pip |
| 150 | - Using Docker container |
Filip Pytloun | 21d9af9 | 2016-08-30 08:13:39 +0200 | [diff] [blame] | 151 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 152 | Install ``docker-compose`` using Docker (default is distribution package): |
Filip Pytloun | 96fc0cc | 2016-08-29 16:01:10 +0200 | [diff] [blame] | 153 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 154 | .. code-block:: yaml |
Filip Pytloun | 96fc0cc | 2016-08-29 16:01:10 +0200 | [diff] [blame] | 155 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 156 | docker: |
| 157 | client: |
| 158 | compose: |
| 159 | source: |
| 160 | engine: docker |
| 161 | image: docker/compose:1.8.0 |
| 162 | django_web: |
| 163 | # Run up action, any positional argument to docker-compose CLI |
| 164 | # If not defined, only docker-compose.yml is generated |
| 165 | status: up |
| 166 | # Run image pull every time state is run triggering container |
| 167 | # restart in case it's changed |
| 168 | pull: true |
| 169 | environment: |
| 170 | SOMEVAR: somevalue |
| 171 | service: |
| 172 | db: |
| 173 | image: postgres |
| 174 | web: |
| 175 | image: djangoapp |
| 176 | volumes: |
| 177 | - /srv/volumes/django:/srv/django |
| 178 | ports: |
| 179 | - 8000:8000 |
| 180 | depends_on: |
| 181 | - db |
Filip Pytloun | 96fc0cc | 2016-08-29 16:01:10 +0200 | [diff] [blame] | 182 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 183 | * Registry |
Richard Felkl | caba132 | 2017-10-03 15:35:28 +0200 | [diff] [blame] | 184 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 185 | .. code-block:: yaml |
Richard Felkl | caba132 | 2017-10-03 15:35:28 +0200 | [diff] [blame] | 186 | |
| 187 | docker: |
| 188 | client: |
| 189 | registry: |
| 190 | target_registry: apt:5000 |
| 191 | image: |
| 192 | - registry: docker |
| 193 | name: compose:1.8.0 |
| 194 | - registry: tcpcloud |
| 195 | name: jenkins:latest |
| 196 | - registry: "" |
| 197 | name: registry:2 |
| 198 | target_registry: myregistry |
| 199 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 200 | Docker Service configuration samples |
| 201 | ==================================== |
Filip Pytloun | a4f6c2f | 2017-04-13 12:00:01 +0200 | [diff] [blame] | 202 | |
Filip Pytloun | ab52ede | 2016-11-02 16:59:49 +0100 | [diff] [blame] | 203 | To deploy service in Swarm mode, you can use ``docker.client.service``: |
| 204 | |
| 205 | .. code-block:: yaml |
| 206 | |
| 207 | parameters: |
| 208 | docker: |
| 209 | client: |
| 210 | service: |
| 211 | postgresql: |
| 212 | environment: |
| 213 | POSTGRES_USER: user |
| 214 | POSTGRES_PASSWORD: password |
| 215 | POSTGRES_DB: mydb |
| 216 | restart: |
| 217 | condition: on-failure |
| 218 | image: "postgres:9.5" |
| 219 | ports: |
| 220 | - 5432:5432 |
| 221 | volume: |
| 222 | data: |
| 223 | type: bind |
| 224 | source: /srv/volumes/postgresql/maas |
| 225 | destination: /var/lib/postgresql/data |
| 226 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 227 | Docker Registry configuration samples |
| 228 | ===================================== |
Filip Pytloun | 96fc0cc | 2016-08-29 16:01:10 +0200 | [diff] [blame] | 229 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 230 | * Basic Docker Registry configuration: |
Filip Pytloun | baf94c9 | 2016-06-07 18:07:17 +0200 | [diff] [blame] | 231 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 232 | .. code-block:: yaml |
Filip Pytloun | baf94c9 | 2016-06-07 18:07:17 +0200 | [diff] [blame] | 233 | |
| 234 | docker: |
| 235 | registry: |
| 236 | log: |
| 237 | level: debug |
| 238 | formatter: json |
| 239 | cache: |
| 240 | engine: redis |
| 241 | host: localhost |
| 242 | storage: |
| 243 | engine: filesystem |
| 244 | root: /srv/docker/registry |
| 245 | bind: |
| 246 | host: 0.0.0.0 |
| 247 | port: 5000 |
| 248 | hook: |
| 249 | mail: |
| 250 | levels: |
| 251 | - panic |
| 252 | # Options are rendered as yaml as is so use hook-specific options here |
| 253 | options: |
| 254 | smtp: |
| 255 | addr: smtp.sendhost.com:25 |
| 256 | username: sendername |
| 257 | password: password |
| 258 | insecure: true |
| 259 | from: name@sendhost.com |
| 260 | to: |
| 261 | - name@receivehost.com |
| 262 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 263 | * Docker login to private registry: |
marco | 85b72a6 | 2016-07-07 13:08:33 +0200 | [diff] [blame] | 264 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 265 | .. code-block:: yaml |
marco | 85b72a6 | 2016-07-07 13:08:33 +0200 | [diff] [blame] | 266 | |
| 267 | docker: |
| 268 | host: |
| 269 | enabled: true |
| 270 | registry: |
| 271 | first: |
| 272 | address: private.docker.com |
| 273 | user: username |
| 274 | password: password |
| 275 | second: |
| 276 | address: private2.docker.com |
| 277 | user: username2 |
| 278 | password: password2 |
Michael Kutý | 1764940 | 2016-03-19 23:57:43 +0100 | [diff] [blame] | 279 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 280 | Docker container service management configuration samples |
| 281 | ========================================================= |
Aleš Komárek | 028b885 | 2017-04-11 13:10:58 +0200 | [diff] [blame] | 282 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 283 | * Start a service in a container: |
Pavel Svimbersky | 27816ab | 2017-12-18 15:13:49 +0100 | [diff] [blame] | 284 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 285 | .. code-block:: yaml |
Pavel Svimbersky | 27816ab | 2017-12-18 15:13:49 +0100 | [diff] [blame] | 286 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 287 | contrail_control_started: |
| 288 | dockerng_service.start: |
| 289 | - container: f020d0d3efa8 |
| 290 | - service: contrail-control |
Pavel Svimbersky | 27816ab | 2017-12-18 15:13:49 +0100 | [diff] [blame] | 291 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 292 | or |
Pavel Svimbersky | 27816ab | 2017-12-18 15:13:49 +0100 | [diff] [blame] | 293 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 294 | .. code-block:: yaml |
Pavel Svimbersky | 27816ab | 2017-12-18 15:13:49 +0100 | [diff] [blame] | 295 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 296 | contrail_control_started: |
| 297 | dockerng_service.start: |
| 298 | - container: contrail_controller |
| 299 | - service: contrail-control |
Pavel Svimbersky | 27816ab | 2017-12-18 15:13:49 +0100 | [diff] [blame] | 300 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 301 | * Stop a service in a container: |
Pavel Svimbersky | 27816ab | 2017-12-18 15:13:49 +0100 | [diff] [blame] | 302 | |
| 303 | .. code-block:: yaml |
| 304 | |
| 305 | contrail_control_stoped: |
| 306 | dockerng_service.stop: |
| 307 | - container: f020d0d3efa8 |
| 308 | - service: contrail-control |
| 309 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 310 | * Restart a service in a container: |
Pavel Svimbersky | 27816ab | 2017-12-18 15:13:49 +0100 | [diff] [blame] | 311 | |
| 312 | .. code-block:: yaml |
| 313 | |
| 314 | contrail_control_restart: |
| 315 | dockerng_service.restart: |
| 316 | - container: f020d0d3efa8 |
| 317 | - service: contrail-control |
| 318 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 319 | * Enable a service in a container: |
Pavel Svimbersky | 27816ab | 2017-12-18 15:13:49 +0100 | [diff] [blame] | 320 | |
| 321 | .. code-block:: yaml |
| 322 | |
| 323 | contrail_control_enable: |
| 324 | dockerng_service.enable: |
| 325 | - container: f020d0d3efa8 |
| 326 | - service: contrail-control |
| 327 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 328 | * Disable a service in a container: |
Pavel Svimbersky | 27816ab | 2017-12-18 15:13:49 +0100 | [diff] [blame] | 329 | |
| 330 | .. code-block:: yaml |
| 331 | |
| 332 | contrail_control_disable: |
| 333 | dockerng_service.disable: |
| 334 | - container: f020d0d3efa8 |
| 335 | - service: contrail-control |
| 336 | |
Kostiantyn Ovchynnykov | dc83bba | 2019-08-18 15:51:00 +0300 | [diff] [blame] | 337 | Use registry that requires authentication |
| 338 | ========================================================= |
| 339 | |
| 340 | * Define private Docker registry and credentials for it: |
| 341 | |
| 342 | .. code-block:: yaml |
| 343 | |
| 344 | docker: |
| 345 | host: |
| 346 | insecure_registries: |
| 347 | - 192.168.0.254:5000 |
| 348 | registry: |
| 349 | my_registry: |
| 350 | address: 192.168.0.254:5000 |
| 351 | user: registry_user |
| 352 | password: registry_password |
| 353 | |
| 354 | * Specify that services in stack require registry with authentication |
| 355 | |
| 356 | .. code-block:: yaml |
| 357 | |
| 358 | docker: |
| 359 | client: |
| 360 | stack: |
| 361 | myapp: |
| 362 | registry_auth: True |
| 363 | |
OlgaGusarenko | 0b8d96e | 2018-06-29 16:21:01 +0300 | [diff] [blame] | 364 | **Read more** |
Michael Kutý | 1764940 | 2016-03-19 23:57:43 +0100 | [diff] [blame] | 365 | |
| 366 | * https://docs.docker.com/installation/ubuntulinux/ |
| 367 | * https://github.com/saltstack-formulas/docker-formula |