blob: 2157a2bf0a2a736641a140e544bd031e40901f85 [file] [log] [blame]
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +03001=====
2Usage
3=====
Michael Kutý17649402016-03-19 23:57:43 +01004
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +03005Docker is a platform for developers and system administrators for developing,
6shipping, and running applications. Docker enables you to quickly assemble
7applications from components and eliminates the friction that can come when
8shipping the code. Also, with Docker, you get your code tested and deployed
9into production as fast as possible.
Michael Kutý17649402016-03-19 23:57:43 +010010
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030011This file provides the sample configurations for different use cases.
Michael Kutý17649402016-03-19 23:57:43 +010012
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030013Docker host configuration samples
14=================================
Michael Kutý17649402016-03-19 23:57:43 +010015
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030016* Docker host sample pillar configuration:
Filip Pytloune27a90d2016-08-29 14:08:34 +020017
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030018 .. code-block:: yaml
Michael Kutý17649402016-03-19 23:57:43 +010019
20 docker:
21 host:
22 enabled: true
Tomáš Kukrál55cbec72017-06-19 17:21:04 +020023 options:
24 bip: 172.31.255.1/16
Tomáš Kukrálb2debce2017-09-22 08:17:39 +020025 insecure-registries:
Tomáš Kukrál55cbec72017-06-19 17:21:04 +020026 - 127.0.0.1
27 - 10.0.0.1
28 log-driver: json-file
29 log-opts:
30 max-size: 50m
Michael Kutý17649402016-03-19 23:57:43 +010031
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030032* Proxy configuration for Docker host:
Aleš Komárek028b8852017-04-11 13:10:58 +020033
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030034 .. code-block:: yaml
Tomáš Kukrál19a39602017-08-27 22:21:47 +020035
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
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030048Docker Swarm configuration samples
49==================================
Filip Pytloun2720a0d2016-11-02 14:15:55 +010050
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030051Role can be master, manager, or worker. Master is the first manager that
Filip Pytloun2720a0d2016-11-02 14:15:55 +010052will initialize the swarm.
53
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030054* Metadata for manager (the first node):
Filip Pytloun2720a0d2016-11-02 14:15:55 +010055
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030056 .. code-block:: yaml
Filip Pytloun2720a0d2016-11-02 14:15:55 +010057
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
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030068* Metadata for worker:
Filip Pytloun2720a0d2016-11-02 14:15:55 +010069
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030070 .. code-block:: yaml
Filip Pytloun2720a0d2016-11-02 14:15:55 +010071
72 docker:
73 host:
74 enabled: true
75 swarm:
76 role: worker
77 master:
78 host: 192.168.1.5
79 port: 2377
80
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030081The 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
83you have ``docker_swarm_`` grains available.
Filip Pytloun2720a0d2016-11-02 14:15:55 +010084
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030085Docker client configuration samples
86===================================
Michael Kutý17649402016-03-19 23:57:43 +010087
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030088* Container:
Filip Pytloun96fc0cc2016-08-29 16:01:10 +020089
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +030090 .. code-block:: yaml
Filip Pytloun96fc0cc2016-08-29 16:01:10 +020091
Michael Kutý17649402016-03-19 23:57:43 +010092 docker:
Filip Pytloune27a90d2016-08-29 14:08:34 +020093 client:
Michael Kutý17649402016-03-19 23:57:43 +010094 container:
Filip Pytloun87169542016-08-29 13:38:30 +020095 jenkins:
96 # Don't start automatically
97 start: false
98 restart: unless-stopped
99 image: jenkins:2.7.1
Michael Kutý17649402016-03-19 23:57:43 +0100100 ports:
Filip Pytloun87169542016-08-29 13:38:30 +0200101 - 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ý17649402016-03-19 23:57:43 +0100107
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300108* Docker compose:
Filip Pytloun96fc0cc2016-08-29 16:01:10 +0200109
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300110 The states providing this functionality include:
Filip Pytlouna4f6c2f2017-04-13 12:00:01 +0200111
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300112 - docker.client.stack
113 - docker.client.compose
Filip Pytlouna4f6c2f2017-04-13 12:00:01 +0200114
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300115 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 Pytlouna4f6c2f2017-04-13 12:00:01 +0200118
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300119 * Stack:
Filip Pytlouna4f6c2f2017-04-13 12:00:01 +0200120
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300121 .. code-block:: yaml
Filip Pytlouna4f6c2f2017-04-13 12:00:01 +0200122
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300123 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 Pytlouna4f6c2f2017-04-13 12:00:01 +0200143
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300144 * Compose
Filip Pytlouna4f6c2f2017-04-13 12:00:01 +0200145
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300146 You can install ``docker-compose`` using one of the following options:
Filip Pytloun21d9af92016-08-30 08:13:39 +0200147
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300148 - Distribution package (default)
149 - Using Pip
150 - Using Docker container
Filip Pytloun21d9af92016-08-30 08:13:39 +0200151
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300152 Install ``docker-compose`` using Docker (default is distribution package):
Filip Pytloun96fc0cc2016-08-29 16:01:10 +0200153
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300154 .. code-block:: yaml
Filip Pytloun96fc0cc2016-08-29 16:01:10 +0200155
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300156 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 Pytloun96fc0cc2016-08-29 16:01:10 +0200182
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300183* Registry
Richard Felklcaba1322017-10-03 15:35:28 +0200184
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300185 .. code-block:: yaml
Richard Felklcaba1322017-10-03 15:35:28 +0200186
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
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300200Docker Service configuration samples
201====================================
Filip Pytlouna4f6c2f2017-04-13 12:00:01 +0200202
Filip Pytlounab52ede2016-11-02 16:59:49 +0100203To 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
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300227Docker Registry configuration samples
228=====================================
Filip Pytloun96fc0cc2016-08-29 16:01:10 +0200229
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300230* Basic Docker Registry configuration:
Filip Pytlounbaf94c92016-06-07 18:07:17 +0200231
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300232 .. code-block:: yaml
Filip Pytlounbaf94c92016-06-07 18:07:17 +0200233
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
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300263* Docker login to private registry:
marco85b72a62016-07-07 13:08:33 +0200264
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300265 .. code-block:: yaml
marco85b72a62016-07-07 13:08:33 +0200266
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ý17649402016-03-19 23:57:43 +0100279
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300280Docker container service management configuration samples
281=========================================================
Aleš Komárek028b8852017-04-11 13:10:58 +0200282
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300283* Start a service in a container:
Pavel Svimbersky27816ab2017-12-18 15:13:49 +0100284
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300285 .. code-block:: yaml
Pavel Svimbersky27816ab2017-12-18 15:13:49 +0100286
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300287 contrail_control_started:
288 dockerng_service.start:
289 - container: f020d0d3efa8
290 - service: contrail-control
Pavel Svimbersky27816ab2017-12-18 15:13:49 +0100291
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300292 or
Pavel Svimbersky27816ab2017-12-18 15:13:49 +0100293
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300294 .. code-block:: yaml
Pavel Svimbersky27816ab2017-12-18 15:13:49 +0100295
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300296 contrail_control_started:
297 dockerng_service.start:
298 - container: contrail_controller
299 - service: contrail-control
Pavel Svimbersky27816ab2017-12-18 15:13:49 +0100300
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300301* Stop a service in a container:
Pavel Svimbersky27816ab2017-12-18 15:13:49 +0100302
303.. code-block:: yaml
304
305 contrail_control_stoped:
306 dockerng_service.stop:
307 - container: f020d0d3efa8
308 - service: contrail-control
309
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300310* Restart a service in a container:
Pavel Svimbersky27816ab2017-12-18 15:13:49 +0100311
312.. code-block:: yaml
313
314 contrail_control_restart:
315 dockerng_service.restart:
316 - container: f020d0d3efa8
317 - service: contrail-control
318
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300319* Enable a service in a container:
Pavel Svimbersky27816ab2017-12-18 15:13:49 +0100320
321.. code-block:: yaml
322
323 contrail_control_enable:
324 dockerng_service.enable:
325 - container: f020d0d3efa8
326 - service: contrail-control
327
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300328* Disable a service in a container:
Pavel Svimbersky27816ab2017-12-18 15:13:49 +0100329
330.. code-block:: yaml
331
332 contrail_control_disable:
333 dockerng_service.disable:
334 - container: f020d0d3efa8
335 - service: contrail-control
336
OlgaGusarenko0b8d96e2018-06-29 16:21:01 +0300337**Read more**
Michael Kutý17649402016-03-19 23:57:43 +0100338
339* https://docs.docker.com/installation/ubuntulinux/
340* https://github.com/saltstack-formulas/docker-formula