docker-app 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docker-app.gemspec +36 -0
- data/exe/docker-app +20 -0
- data/lib/docker_app.rb +23 -0
- data/lib/docker_app/builder/packer.rb +105 -0
- data/lib/docker_app/chef/.chef/knife.rb +118 -0
- data/lib/docker_app/chef/chef_build_image.rb +55 -0
- data/lib/docker_app/chef/chef_destroy_container.rb +13 -0
- data/lib/docker_app/chef/chef_destroy_image.rb +17 -0
- data/lib/docker_app/chef/chef_exec_container.rb +16 -0
- data/lib/docker_app/chef/chef_run_container.rb +64 -0
- data/lib/docker_app/chef/install_container_service.rb +14 -0
- data/lib/docker_app/cli.rb +502 -0
- data/lib/docker_app/command.rb +16 -0
- data/lib/docker_app/config.rb +249 -0
- data/lib/docker_app/config/dsl.rb +64 -0
- data/lib/docker_app/config/helpers.rb +99 -0
- data/lib/docker_app/manager_container.rb +376 -0
- data/lib/docker_app/manager_image.rb +119 -0
- data/lib/docker_app/manager_swarm.rb +66 -0
- data/lib/docker_app/provisioner/base.rb +179 -0
- data/lib/docker_app/provisioner/chef.rb +93 -0
- data/lib/docker_app/server_settings.rb +361 -0
- data/lib/docker_app/version.rb +3 -0
- data/lib/templates/example-chef/.chef/knife.rb +5 -0
- data/lib/templates/example-chef/config.rb.erb +18 -0
- data/lib/templates/example-chef/servers/server1/.chef/knife.rb +8 -0
- data/lib/templates/example-chef/servers/server1/config.rb.erb +54 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/README.md +1 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/metadata.rb.erb +8 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/recipes/build.rb +10 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/recipes/install.rb +36 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/recipes/install_host.rb +9 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/templates/index.html.erb +5 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/templates/nginx-sites/default.conf.erb +45 -0
- data/readme.md +853 -0
- data/readme_developers.md +54 -0
- metadata +129 -0
@@ -0,0 +1 @@
|
|
1
|
+
# sample server
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
## nginx default server
|
3
|
+
template "/etc/nginx/conf.d/default.conf" do
|
4
|
+
source "nginx-sites/default.conf.erb"
|
5
|
+
|
6
|
+
#owner 'root'
|
7
|
+
#group 'root'
|
8
|
+
|
9
|
+
mode '0775'
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
template "/usr/share/nginx/html/index.html" do
|
14
|
+
source "index.html.erb"
|
15
|
+
|
16
|
+
#owner 'root'
|
17
|
+
#group 'root'
|
18
|
+
|
19
|
+
mode '0775'
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
#
|
26
|
+
bash 'reload nginx' do
|
27
|
+
code <<-EOH
|
28
|
+
service nginx reload
|
29
|
+
EOH
|
30
|
+
|
31
|
+
ignore_failure true
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
#command '/etc/init.d/nginx reload'
|
36
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
server {
|
2
|
+
listen 80;
|
3
|
+
server_name localhost ;
|
4
|
+
|
5
|
+
#charset koi8-r;
|
6
|
+
#access_log /var/log/nginx/log/access.log main;
|
7
|
+
|
8
|
+
location / {
|
9
|
+
root /usr/share/nginx/html;
|
10
|
+
index index.html index.htm;
|
11
|
+
}
|
12
|
+
|
13
|
+
#error_page 404 /404.html;
|
14
|
+
|
15
|
+
# redirect server error pages to the static page /50x.html
|
16
|
+
#
|
17
|
+
error_page 500 502 503 504 /50x.html;
|
18
|
+
location = /50x.html {
|
19
|
+
root /usr/share/nginx/html;
|
20
|
+
}
|
21
|
+
|
22
|
+
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
|
23
|
+
#
|
24
|
+
#location ~ \.php$ {
|
25
|
+
# proxy_pass http://127.0.0.1;
|
26
|
+
#}
|
27
|
+
|
28
|
+
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
|
29
|
+
#
|
30
|
+
#location ~ \.php$ {
|
31
|
+
# root html;
|
32
|
+
# fastcgi_pass 127.0.0.1:9000;
|
33
|
+
# fastcgi_index index.php;
|
34
|
+
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
|
35
|
+
# include fastcgi_params;
|
36
|
+
#}
|
37
|
+
|
38
|
+
# deny access to .htaccess files, if Apache's document root
|
39
|
+
# concurs with nginx's one
|
40
|
+
#
|
41
|
+
#location ~ /\.ht {
|
42
|
+
# deny all;
|
43
|
+
#}
|
44
|
+
}
|
45
|
+
|
data/readme.md
ADDED
@@ -0,0 +1,853 @@
|
|
1
|
+
# Docker app
|
2
|
+
|
3
|
+
Docker app is a tool to install and setup Docker containers.
|
4
|
+
It uses Dockerfile, Chef and other provisioning tools.
|
5
|
+
|
6
|
+
Features:
|
7
|
+
* Config files are in Ruby.
|
8
|
+
* Manage complexity of running Docker containers for your environment in one place.
|
9
|
+
* Manage multiple containers
|
10
|
+
|
11
|
+
|
12
|
+
Other tools:
|
13
|
+
* docker-composer - with configs in yml
|
14
|
+
|
15
|
+
|
16
|
+
Docker-app is similar to docker-compose but has some more functionality to customize installation of servers on the host.
|
17
|
+
|
18
|
+
|
19
|
+
# Overview
|
20
|
+
|
21
|
+
Process of installing server in Docker container consists of the following stages:
|
22
|
+
|
23
|
+
Process of building and running container on the host machine:
|
24
|
+
* Build Docker image
|
25
|
+
* it will create a Docker image on the host machine
|
26
|
+
* build using Dockerfile or Chef provisioning
|
27
|
+
|
28
|
+
* Run Docker container
|
29
|
+
* provision host machine - run scripts locally on the host machine. It can be shell script of Chef recipe
|
30
|
+
* run container - `docker run`
|
31
|
+
* provision container - run script inside the container. It can be shell script of Chef recipe
|
32
|
+
|
33
|
+
* Install systemd service on the host machine to run Docker container automatically (optional)
|
34
|
+
|
35
|
+
* Start/Stop container
|
36
|
+
|
37
|
+
* Destroy container
|
38
|
+
|
39
|
+
* Destroy image
|
40
|
+
|
41
|
+
|
42
|
+
Concepts of running Docker containers:
|
43
|
+
* you can rerun containers without losing data. Data is stored on the host machine and shared with container.
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
Build Docker image:
|
49
|
+
* from Dockerfile
|
50
|
+
* Chef provisioning (machine_image)
|
51
|
+
|
52
|
+
Provision during installation container on the host machine by:
|
53
|
+
* running shell script inside container
|
54
|
+
* running Chef script inside container with Chef provisioning
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
# Installation
|
59
|
+
|
60
|
+
* Install gem:
|
61
|
+
```
|
62
|
+
gem install docker-app
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
# Quickstart
|
68
|
+
|
69
|
+
We will build and run a simple Docker container with Nginx server.
|
70
|
+
|
71
|
+
* install gem
|
72
|
+
|
73
|
+
```
|
74
|
+
gem install docker-app
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
* generate directory structure using generator
|
79
|
+
|
80
|
+
```
|
81
|
+
docker-app generate --name=nginx --type=chef
|
82
|
+
```
|
83
|
+
|
84
|
+
it will create a folder `nginx` with necessary directory structure inside.
|
85
|
+
|
86
|
+
|
87
|
+
* in the folder edit config file `config.rb` with common settings
|
88
|
+
|
89
|
+
```
|
90
|
+
common({
|
91
|
+
'prefix' => "example-",
|
92
|
+
'image_prefix' => 'example-',
|
93
|
+
'dir_data' => '/disk3/data/my-examples/',
|
94
|
+
|
95
|
+
})
|
96
|
+
|
97
|
+
servers({
|
98
|
+
'nginx'=>{
|
99
|
+
# some server options here
|
100
|
+
},
|
101
|
+
|
102
|
+
|
103
|
+
})
|
104
|
+
|
105
|
+
|
106
|
+
base({
|
107
|
+
|
108
|
+
})
|
109
|
+
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
* edit custom settings for the server in file `servers/nginx/config.rb`
|
114
|
+
|
115
|
+
```
|
116
|
+
|
117
|
+
add 'build', {
|
118
|
+
"image_name" => "nginx",
|
119
|
+
'build_type' => 'chef',
|
120
|
+
"base_image" => { "name" => "nginx", "repository" => "nginx", "tag" => "1.10" },
|
121
|
+
|
122
|
+
}
|
123
|
+
|
124
|
+
add 'install', {
|
125
|
+
"host" => { 'script_type' => 'chef_recipe', 'script' => 'install_host', },
|
126
|
+
"node" => { 'script_type' => 'chef_recipe', 'script' => 'install', }
|
127
|
+
}
|
128
|
+
|
129
|
+
add 'docker', {
|
130
|
+
"command"=> "nginx -g 'daemon off;'",
|
131
|
+
'ports' => [
|
132
|
+
[8080,80],
|
133
|
+
],
|
134
|
+
'volumes' => [
|
135
|
+
['html', '/usr/share/nginx/html'],
|
136
|
+
['log/nginx', '/var/log/nginx/'],
|
137
|
+
],
|
138
|
+
'links' => [ ]
|
139
|
+
}
|
140
|
+
|
141
|
+
add 'attributes', {
|
142
|
+
'nginx' =>{
|
143
|
+
"sitename" =>"mysite.local"
|
144
|
+
},
|
145
|
+
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
```
|
151
|
+
|
152
|
+
* build Docker image
|
153
|
+
|
154
|
+
```
|
155
|
+
# from the folder with project
|
156
|
+
|
157
|
+
docker-app build
|
158
|
+
```
|
159
|
+
|
160
|
+
* run container
|
161
|
+
|
162
|
+
```
|
163
|
+
docker-app up
|
164
|
+
```
|
165
|
+
|
166
|
+
* check container is running
|
167
|
+
```
|
168
|
+
docker ps
|
169
|
+
|
170
|
+
# see container named example-nginx
|
171
|
+
```
|
172
|
+
|
173
|
+
* access container
|
174
|
+
|
175
|
+
```
|
176
|
+
docker exec -ti example-nginx /bin/bash
|
177
|
+
```
|
178
|
+
|
179
|
+
* access container from browser
|
180
|
+
|
181
|
+
```
|
182
|
+
http://localhost:8080
|
183
|
+
```
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
# Install Docker container. Overview
|
189
|
+
|
190
|
+
Process:
|
191
|
+
* Create container - docker create
|
192
|
+
* setup network and other settings for container
|
193
|
+
|
194
|
+
* run provision to setup host machine. Script is running on the host machine.
|
195
|
+
```
|
196
|
+
{
|
197
|
+
'provision'=>{
|
198
|
+
'setup' => [
|
199
|
+
{type: 'shell', ..},
|
200
|
+
..
|
201
|
+
]
|
202
|
+
...
|
203
|
+
}
|
204
|
+
```
|
205
|
+
|
206
|
+
* run provision to setup created (not running) container.
|
207
|
+
Run script to copy/update files in container.
|
208
|
+
|
209
|
+
```
|
210
|
+
{
|
211
|
+
'provision'=>{
|
212
|
+
'setup'=> [
|
213
|
+
{type: 'ruby', <<script_options>>},
|
214
|
+
..
|
215
|
+
]
|
216
|
+
...
|
217
|
+
}
|
218
|
+
```
|
219
|
+
|
220
|
+
* run container with `docker run`. Specify env variables, hostname and other options
|
221
|
+
|
222
|
+
* first provision of container - bootstrap script. Run script from inside running container only once.
|
223
|
+
Script should be located inside container.
|
224
|
+
```
|
225
|
+
{
|
226
|
+
'provision'=>{
|
227
|
+
'bootstrap'=> [
|
228
|
+
{type: 'chef', ..},
|
229
|
+
..
|
230
|
+
]
|
231
|
+
}
|
232
|
+
```
|
233
|
+
|
234
|
+
* provision to initialize container.
|
235
|
+
Run script every time after container starts. Script should be located inside container.
|
236
|
+
```
|
237
|
+
{
|
238
|
+
'provision'=>{
|
239
|
+
'init'=> [
|
240
|
+
{type: 'chef'},
|
241
|
+
..
|
242
|
+
]
|
243
|
+
}
|
244
|
+
```
|
245
|
+
|
246
|
+
* Use lock file to make sure the container does not start until the provision is finished.
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
# Basic usage
|
253
|
+
|
254
|
+
# Provision with shell script
|
255
|
+
|
256
|
+
* put scripts in `/path/to/project/ <<server_name>> / scripts / install.sh`
|
257
|
+
|
258
|
+
|
259
|
+
# Provisioning with Chef
|
260
|
+
|
261
|
+
Process of building and running container on the host machine:
|
262
|
+
* Build Docker image
|
263
|
+
* it will create a Docker image on the host machine
|
264
|
+
|
265
|
+
* Run Docker container
|
266
|
+
* provision host machine - run scripts locally on the host machine
|
267
|
+
(recipe install_host.rb)
|
268
|
+
* run container (docker run)
|
269
|
+
* provision container - run script in the container
|
270
|
+
(recipe install.rb)
|
271
|
+
|
272
|
+
* Install systemd service to run Docker container (optional)
|
273
|
+
|
274
|
+
* Start/Stop container
|
275
|
+
|
276
|
+
* Destroy container
|
277
|
+
|
278
|
+
* Destroy image
|
279
|
+
|
280
|
+
|
281
|
+
## Install server with Chef provisioning
|
282
|
+
|
283
|
+
* generate directory structure using generator
|
284
|
+
```
|
285
|
+
docker-app generate --name=nginx --type=chef
|
286
|
+
```
|
287
|
+
|
288
|
+
it will create a folder `nginx`
|
289
|
+
|
290
|
+
* in the folder edit config file `config.rb` with common settings
|
291
|
+
|
292
|
+
```
|
293
|
+
|
294
|
+
```
|
295
|
+
|
296
|
+
* edit custom settings for the server in file `servers/nginx/config.rb`
|
297
|
+
|
298
|
+
```
|
299
|
+
```
|
300
|
+
|
301
|
+
* build Docker image
|
302
|
+
|
303
|
+
```
|
304
|
+
# from the folder with project
|
305
|
+
|
306
|
+
docker-app build
|
307
|
+
```
|
308
|
+
|
309
|
+
* run container
|
310
|
+
|
311
|
+
```
|
312
|
+
docker-app up
|
313
|
+
```
|
314
|
+
|
315
|
+
* check container is running
|
316
|
+
```
|
317
|
+
docker ps
|
318
|
+
```
|
319
|
+
|
320
|
+
* access container from browser
|
321
|
+
|
322
|
+
```
|
323
|
+
http://localhost:8080
|
324
|
+
```
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
|
330
|
+
# Usage
|
331
|
+
|
332
|
+
|
333
|
+
* Build docker image
|
334
|
+
|
335
|
+
```
|
336
|
+
cd /path/to/servers
|
337
|
+
|
338
|
+
docker-app build -s server_name
|
339
|
+
```
|
340
|
+
|
341
|
+
* run docker container
|
342
|
+
|
343
|
+
```
|
344
|
+
cd /path/to/servers
|
345
|
+
|
346
|
+
docker-app run -s server_name
|
347
|
+
```
|
348
|
+
|
349
|
+
it will run container.
|
350
|
+
|
351
|
+
access container:
|
352
|
+
|
353
|
+
```
|
354
|
+
docker exec -ti container_name /bin/bash
|
355
|
+
```
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
# Provision
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
## Run provision after start
|
365
|
+
|
366
|
+
### Run provision from host machine
|
367
|
+
|
368
|
+
Run from outside container
|
369
|
+
|
370
|
+
```
|
371
|
+
'provision' => {
|
372
|
+
"bootstrap" => [
|
373
|
+
{'type' => 'shell', 'run_from'=>'host', 'script'=>'name=myserver ruby myprovision1.rb' }
|
374
|
+
]
|
375
|
+
}
|
376
|
+
|
377
|
+
```
|
378
|
+
|
379
|
+
it will run script `name=myserver ruby myprovision1.rb` from the host machine.
|
380
|
+
|
381
|
+
|
382
|
+
### Provision with Chef
|
383
|
+
|
384
|
+
* in config file
|
385
|
+
```
|
386
|
+
'provision' => {
|
387
|
+
"bootstrap" => [
|
388
|
+
{'type' => 'chef', "script"=>"", "dir_base"=>"/opt/bootstrap", "recipe"=>"server::bootstrap" },
|
389
|
+
]
|
390
|
+
},
|
391
|
+
```
|
392
|
+
|
393
|
+
it will run chef provisioning:
|
394
|
+
```
|
395
|
+
cd /opt/bootstrap/ && chef-client -z -j /opt/bootstrap/config.json --override-runlist "recipe[server::bootstrap]"
|
396
|
+
|
397
|
+
```
|
398
|
+
|
399
|
+
config file with attributes (`/opt/bootstrap/config.json`) for chef-client is generated automatically.
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
## Development
|
404
|
+
|
405
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
406
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
407
|
+
|
408
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
# Configuration
|
414
|
+
|
415
|
+
* edit config.rb in your root folder
|
416
|
+
|
417
|
+
You can put all settings in this config.rb file and/or use config.rb file in each server's folder.
|
418
|
+
|
419
|
+
Config files:
|
420
|
+
```
|
421
|
+
/path/to/project/config.rb
|
422
|
+
/path/to/project/servers/server1/config.rb
|
423
|
+
/path/to/project/servers/server2/config.rb
|
424
|
+
```
|
425
|
+
|
426
|
+
|
427
|
+
## config.rb
|
428
|
+
|
429
|
+
|
430
|
+
* CHEF_COOKBOOKS - list of paths to chef cookbooks
|
431
|
+
|
432
|
+
|
433
|
+
# Build Docker image
|
434
|
+
|
435
|
+
Build types:
|
436
|
+
* 'none' - no build required
|
437
|
+
* 'Dockerfile' - using Dockerfile and docker build command
|
438
|
+
* 'chef' - using Chef provisioning (gem chef-provisioning-docker)
|
439
|
+
* 'packer' - using Packer tool
|
440
|
+
|
441
|
+
|
442
|
+
# Chef provisioning
|
443
|
+
|
444
|
+
* add additional paths for cookbooks
|
445
|
+
|
446
|
+
in folder with servers:
|
447
|
+
|
448
|
+
```
|
449
|
+
# /path/to/my/servers/.chef/knife.rb
|
450
|
+
|
451
|
+
cookbook_path cookbook_path+[
|
452
|
+
'/path/to/my/cookbooks',
|
453
|
+
'/path/to/my/other/cookbooks',
|
454
|
+
]
|
455
|
+
|
456
|
+
```
|
457
|
+
|
458
|
+
|
459
|
+
# Build Docker container with Chef
|
460
|
+
|
461
|
+
Example of building Docker container with Chef.
|
462
|
+
|
463
|
+
Assume that our server name is 'nginx'.
|
464
|
+
|
465
|
+
|
466
|
+
* edit config file 'myserver/config.rb'
|
467
|
+
|
468
|
+
```
|
469
|
+
####
|
470
|
+
```
|
471
|
+
|
472
|
+
* Chef recipes
|
473
|
+
* cookbooks/nginx/recipes/build.rb
|
474
|
+
place chef resources to be included in the Docker image
|
475
|
+
|
476
|
+
* cookbooks/nginx/recipes/install.rb
|
477
|
+
|
478
|
+
* cookbooks/nginx/recipes/install_host.rb
|
479
|
+
|
480
|
+
* build
|
481
|
+
|
482
|
+
```
|
483
|
+
# run from the folder
|
484
|
+
|
485
|
+
docker-app build['nginx']
|
486
|
+
```
|
487
|
+
|
488
|
+
* shared data:
|
489
|
+
/disk3/data/server-api/nginx-front
|
490
|
+
|
491
|
+
data for nginx server:
|
492
|
+
* /etc/nginx/conf.d
|
493
|
+
* /var/www/html
|
494
|
+
* /var/log/nginx
|
495
|
+
|
496
|
+
|
497
|
+
* Main site - /var/www/html ==> /disk3/data/server-api/nginx-front/var/www/html
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
* Config
|
502
|
+
|
503
|
+
|
504
|
+
## Run container
|
505
|
+
|
506
|
+
|
507
|
+
|
508
|
+
## Manage multiple servers
|
509
|
+
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
# Build container
|
516
|
+
|
517
|
+
## Build from Dockerfile
|
518
|
+
|
519
|
+
* config for server
|
520
|
+
```
|
521
|
+
'build' => {
|
522
|
+
'build_type' => 'Dockerfile',
|
523
|
+
"image_name" => "myname",
|
524
|
+
|
525
|
+
"base_image" => {} # not used
|
526
|
+
},
|
527
|
+
```
|
528
|
+
|
529
|
+
|
530
|
+
## Build with Packer
|
531
|
+
|
532
|
+
* config for server
|
533
|
+
```
|
534
|
+
'build' => {
|
535
|
+
'build_type' => 'packer',
|
536
|
+
"image_name" => "myname",
|
537
|
+
|
538
|
+
"base_image" => {
|
539
|
+
"name" => "nginx",
|
540
|
+
"repository" => "nginx",
|
541
|
+
"tag" => "1.10"
|
542
|
+
},
|
543
|
+
|
544
|
+
"packer" => { options for packer }
|
545
|
+
},
|
546
|
+
```
|
547
|
+
|
548
|
+
* options for packer
|
549
|
+
|
550
|
+
* cookbook_paths - list of paths
|
551
|
+
* recipe_name
|
552
|
+
|
553
|
+
|
554
|
+
* examples:
|
555
|
+
```
|
556
|
+
```
|
557
|
+
|
558
|
+
|
559
|
+
# Run container
|
560
|
+
|
561
|
+
|
562
|
+
## Run from existing image
|
563
|
+
|
564
|
+
* config for server
|
565
|
+
```
|
566
|
+
'build' => {
|
567
|
+
'build_type' => 'none',
|
568
|
+
"image_name" => "myname",
|
569
|
+
|
570
|
+
"base_image" => {
|
571
|
+
"name" => "mysql",
|
572
|
+
"repository" => "mysql",
|
573
|
+
"tag" => "3.4.9"
|
574
|
+
},
|
575
|
+
},
|
576
|
+
|
577
|
+
```
|
578
|
+
|
579
|
+
it will NOT build a new Docker image.
|
580
|
+
|
581
|
+
|
582
|
+
|
583
|
+
## Run Docker container with Chef
|
584
|
+
|
585
|
+
* run recipe install_host which runs on the host machine (not in container)
|
586
|
+
* run recipe install which runs from within the running container
|
587
|
+
|
588
|
+
|
589
|
+
|
590
|
+
# Start Docker container
|
591
|
+
|
592
|
+
docker-app start -s server_name
|
593
|
+
|
594
|
+
it starts docker container which was previously created.
|
595
|
+
|
596
|
+
Process:
|
597
|
+
* Start docker container container with `docker start ..`
|
598
|
+
* Provision container
|
599
|
+
|
600
|
+
|
601
|
+
|
602
|
+
# Other tools
|
603
|
+
|
604
|
+
* packer - https://github.com/mitchellh/packer
|
605
|
+
|
606
|
+
Packer is a tool for creating machine images for multiple platforms from a single source configuration.
|
607
|
+
|
608
|
+
|
609
|
+
|
610
|
+
# Docker options for running container
|
611
|
+
|
612
|
+
* `run_extra_options` - additional options for docker run command
|
613
|
+
|
614
|
+
* hostname
|
615
|
+
|
616
|
+
```
|
617
|
+
{
|
618
|
+
..
|
619
|
+
servers({
|
620
|
+
'zookeeper'=>{
|
621
|
+
...
|
622
|
+
'docker'=> {
|
623
|
+
...
|
624
|
+
'run_extra_options'=>'--hostname zookeeper'
|
625
|
+
}
|
626
|
+
}
|
627
|
+
```
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
# Clear cache
|
632
|
+
|
633
|
+
Sometimes you need to clear cache with server info in chef-zero server
|
634
|
+
|
635
|
+
```
|
636
|
+
docker-app clear_cache
|
637
|
+
```
|
638
|
+
|
639
|
+
|
640
|
+
# Run in swarm mode
|
641
|
+
|
642
|
+
* commands
|
643
|
+
|
644
|
+
docker-app :up_swarm
|
645
|
+
|
646
|
+
docker-app :destroy_swarm
|
647
|
+
|
648
|
+
|
649
|
+
* config
|
650
|
+
|
651
|
+
```
|
652
|
+
docker: {
|
653
|
+
# options here...
|
654
|
+
}
|
655
|
+
```
|
656
|
+
|
657
|
+
* swarm_network - network name
|
658
|
+
* swarm_options - options to pass to docker service create command
|
659
|
+
|
660
|
+
|
661
|
+
|
662
|
+
# Options
|
663
|
+
|
664
|
+
## prefix
|
665
|
+
|
666
|
+
prefix for image names, container names, and service names (for swarm mode)
|
667
|
+
|
668
|
+
* prefix - common prefix. Added to all names
|
669
|
+
* container_prefix - prefix for containers
|
670
|
+
* image_prefix - prefix for images
|
671
|
+
* service_prefix - prefix for services
|
672
|
+
|
673
|
+
|
674
|
+
Example:
|
675
|
+
* container name = $prefix$container_prefix$name
|
676
|
+
|
677
|
+
```
|
678
|
+
prefix='my-'
|
679
|
+
container_prefix='test-'
|
680
|
+
|
681
|
+
container name will be like
|
682
|
+
my-test-redis
|
683
|
+
|
684
|
+
```
|
685
|
+
|
686
|
+
|
687
|
+
|
688
|
+
# Provision
|
689
|
+
|
690
|
+
## Setup container
|
691
|
+
|
692
|
+
### Setup container with shell script
|
693
|
+
|
694
|
+
* run script from the host
|
695
|
+
|
696
|
+
```
|
697
|
+
'provision' => {
|
698
|
+
"setup" => [
|
699
|
+
{ 'type' => 'shell', 'script' => 'scripts/mysetup.sh', },
|
700
|
+
]
|
701
|
+
},
|
702
|
+
```
|
703
|
+
|
704
|
+
* it will run the script
|
705
|
+
```
|
706
|
+
scripts/mysetup.sh
|
707
|
+
```
|
708
|
+
|
709
|
+
## Bootstrap container
|
710
|
+
|
711
|
+
* first provision of container
|
712
|
+
* provision scripts run only once
|
713
|
+
|
714
|
+
|
715
|
+
|
716
|
+
### Bootstrap with shell script
|
717
|
+
|
718
|
+
* Dockerfile
|
719
|
+
|
720
|
+
* include script /opt/bootstrap/bootstrap.sh in container
|
721
|
+
```
|
722
|
+
ADD scripts/bootstrap.sh /opt/bootstrap/
|
723
|
+
|
724
|
+
RUN chmod +x /opt/bootstrap/bootstrap.sh
|
725
|
+
|
726
|
+
```
|
727
|
+
|
728
|
+
* config
|
729
|
+
|
730
|
+
```
|
731
|
+
'provision' => {
|
732
|
+
"bootstrap" => [
|
733
|
+
{ 'type' => 'shell', 'script' => '/opt/bootstrap/bootstrap.sh', },
|
734
|
+
]
|
735
|
+
},
|
736
|
+
|
737
|
+
|
738
|
+
```
|
739
|
+
|
740
|
+
## Provision with chef
|
741
|
+
|
742
|
+
docker-app up -s server_name
|
743
|
+
|
744
|
+
Process:
|
745
|
+
* docker create with docker options
|
746
|
+
* entrypoint: /etc/bootstrap
|
747
|
+
* generate config with node attributes for chef and save it to temp/boostrap-__server__.json
|
748
|
+
* copy config file to container to /opt/bootstrap/config.json
|
749
|
+
* docker start
|
750
|
+
* when container starts it runs /etc/bootstrap which
|
751
|
+
* runs chef-client to provision server first time
|
752
|
+
|
753
|
+
|
754
|
+
|
755
|
+
|
756
|
+
|
757
|
+
|
758
|
+
# Network
|
759
|
+
|
760
|
+
* Docker container can be connected to multiple networks.
|
761
|
+
Container has an IP in each network.
|
762
|
+
|
763
|
+
Docker networks can be created using docker command `docker network create`
|
764
|
+
|
765
|
+
|
766
|
+
Docker-app allows you to manage networks for your container.
|
767
|
+
|
768
|
+
|
769
|
+
|
770
|
+
|
771
|
+
|
772
|
+
|
773
|
+
## multiple networks
|
774
|
+
|
775
|
+
|
776
|
+
* connect to multiple networks and specify default gateway
|
777
|
+
|
778
|
+
define IP in each network.
|
779
|
+
|
780
|
+
it assumes that networks 'my_bridge1' and 'my_overlay1' exist.
|
781
|
+
|
782
|
+
|
783
|
+
```
|
784
|
+
'docker'=> {
|
785
|
+
..
|
786
|
+
'network': {
|
787
|
+
default_gateway: '192.168.1.1',
|
788
|
+
networks: {
|
789
|
+
{net: 'bridge'}, # default docker bridge
|
790
|
+
{net: 'my_bridge1', ip: '10.1.0.12'},
|
791
|
+
{net: 'my_overlay1', ip: '51.1.0.15'},
|
792
|
+
}
|
793
|
+
|
794
|
+
}
|
795
|
+
|
796
|
+
}
|
797
|
+
```
|
798
|
+
|
799
|
+
in this example container will be connected to three networks:
|
800
|
+
* docker default bridge named 'bridge'
|
801
|
+
* custom docker network named 'my_bridge1' with ip='10.1.0.12'
|
802
|
+
* custom docker network named 'my_overlay1'
|
803
|
+
|
804
|
+
|
805
|
+
|
806
|
+
create networks:
|
807
|
+
```
|
808
|
+
docker network create --driver bridge --subnet=51.1.0.0/16 --gateway=51.1.0.1 my_bridge1
|
809
|
+
docker network create -d macvlan --subnet=10.1.0.0/16 --gateway=10.1.0.1 --ip-range=10.1.12.0/24 -o parent=eth0 my_overlay1
|
810
|
+
```
|
811
|
+
|
812
|
+
see docker networks:
|
813
|
+
```
|
814
|
+
docker network ls
|
815
|
+
```
|
816
|
+
|
817
|
+
|
818
|
+
* check
|
819
|
+
```
|
820
|
+
docker exec -ti mycontainer bash
|
821
|
+
|
822
|
+
ip route
|
823
|
+
|
824
|
+
# sample output
|
825
|
+
...
|
826
|
+
|
827
|
+
```
|
828
|
+
|
829
|
+
|
830
|
+
## remove default Docker bridge network
|
831
|
+
|
832
|
+
|
833
|
+
* Container will be connected to two networks and NOT connected to default Docker network 'bridge'
|
834
|
+
|
835
|
+
```
|
836
|
+
'docker'=> {
|
837
|
+
..
|
838
|
+
'network': {
|
839
|
+
networks: {
|
840
|
+
{net: 'bridge', action: 'remove'}, # remove default docker bridge
|
841
|
+
{net: 'mybridge1', ip: '10.1.0.12'},
|
842
|
+
{net: 'my_overlay1', ip: '51.1.0.15'},
|
843
|
+
}
|
844
|
+
}
|
845
|
+
|
846
|
+
}
|
847
|
+
```
|
848
|
+
|
849
|
+
|
850
|
+
# Examples
|
851
|
+
|
852
|
+
* [Nginx with Mysql](https://github.com/maxivak/docker-nginx-mysql-example)
|
853
|
+
|