linux_provision 0.9.3 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.linux_provision.json +3 -3
- data/CHANGES +4 -0
- data/Gemfile +8 -5
- data/Gemfile.lock +57 -9
- data/README.md +129 -35
- data/Vagrantfile +1 -1
- data/demo/.ruby-gemset +1 -0
- data/demo/.ruby-version +1 -0
- data/demo/Dockerfile +107 -0
- data/demo/Gemfile +7 -0
- data/demo/Gemfile.lock +45 -0
- data/demo/Rakefile +7 -0
- data/demo/app.rb +29 -0
- data/demo/bin/start-server.sh +7 -0
- data/demo/config.ru +3 -0
- data/demo/db/migrate/20140610203958_create_notes.rb +14 -0
- data/demo/db/migrate/20140610204302_add_notes.rb +7 -0
- data/demo/db/schema.rb +26 -0
- data/demo/db_setup.rb +11 -0
- data/demo/note.rb +2 -0
- data/demo/supervisord.conf +8 -0
- data/demo/views/index.erb +10 -0
- data/demo/views/layout.erb +8 -0
- data/demo/views/new.erb +12 -0
- data/demo/views/note.erb +3 -0
- data/docker/postgres/Dockerfile +61 -0
- data/docker/postgres/bin/create_db.sh +14 -0
- data/docker/sshd/Dockerfile +28 -0
- data/docker/supervisord/Dockerfile +28 -0
- data/docker/supervisord/supervisord.conf +8 -0
- data/lib/linux_provision/generic_provision.rb +28 -19
- data/lib/linux_provision/linux_provision.rb +7 -165
- data/lib/linux_provision/linux_provision_scripts.sh +65 -21
- data/lib/linux_provision/version.rb +1 -1
- data/presentation/virtualization/01-vagrant/slides.md +381 -0
- data/presentation/virtualization/02-provision/slides.md +400 -0
- data/presentation/virtualization/03-docker/slides.md +208 -0
- data/presentation/virtualization/04-conclusion/slides.md +36 -0
- data/presentation/virtualization/default.css +59 -0
- data/presentation/virtualization/default.tpl +2 -0
- data/presentation/virtualization/images/chef.jpg +0 -0
- data/presentation/virtualization/images/provisioning.jpg +0 -0
- data/presentation/virtualization/images/vagrant.jpg +0 -0
- data/presentation/virtualization/showoff.json +23 -0
- data/presentation/virtualization/simple.tpl +2 -0
- data/spec/linux_install_spec.rb +9 -2
- data/spec/linux_provision_spec.rb +1 -1
- data/stats/viewstats.json +1 -0
- data/thor/demo_scripts.sh +34 -0
- data/thor/docker.thor +31 -0
- data/thor/linux_install.thor +17 -115
- metadata +40 -2
@@ -0,0 +1,400 @@
|
|
1
|
+
|
2
|
+
!SLIDE content transition=cover
|
3
|
+
|
4
|
+
# Provisioning
|
5
|
+
|
6
|
+
>
|
7
|
+
|
8
|
+

|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
!SLIDE title-and-content incremental transition=cover
|
13
|
+
|
14
|
+
# Use Cases
|
15
|
+
|
16
|
+
* Provide **clean clone of production environment**. You can guarantee that your staging server is a exact clone of
|
17
|
+
your production server.
|
18
|
+
|
19
|
+
* **Team of developers working along the globe and on different platforms**. The idea is to do development against
|
20
|
+
unified, easy to replicate virtual platform with same characteristics for all developers.
|
21
|
+
|
22
|
+
* **Configure new workstation for new employee**, e.g. macbook configuration (rvm, ruby, mysql, postgesql, skype, iterm2 etc.)
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
!SLIDE title-and-content incremental transition=zoom
|
27
|
+
|
28
|
+
# Available options for provisioning
|
29
|
+
|
30
|
+
* Create simple shell script
|
31
|
+
* Use chef gem
|
32
|
+
* Use puppet gem (out of scope)
|
33
|
+
* Provisioning from Github: [Boxen](http://boxen.github.com/) - tool for automating and managing Macs with Puppet
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
!SLIDE content transition=cover
|
38
|
+
|
39
|
+
# Chef
|
40
|
+
|
41
|
+
>
|
42
|
+
|
43
|
+

|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
!SLIDE title-and-content transition=cover incremental
|
48
|
+
|
49
|
+
# Chef - what is it?
|
50
|
+
|
51
|
+
> Chef is like unit tests for your servers
|
52
|
+
|
53
|
+
>[Ezra Zygmuntowicz](http://www.linkedin.com/in/ezraz)
|
54
|
+
|
55
|
+
|
56
|
+
* It is **domain specific language** based on ruby.
|
57
|
+
|
58
|
+
* You can write **installation scripts** that will install all required for your platform packages (like homebrew or macport).
|
59
|
+
|
60
|
+
* Could be executed **locally** or on **remote** server.
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
!SLIDE title-and-content incremental transition=cover
|
65
|
+
|
66
|
+
# Types of Chef components
|
67
|
+
|
68
|
+
* **Chef Server** - used to distribute cookbooks, manage and authenticate nodes and query
|
69
|
+
infrastructure information on multiple nodes.
|
70
|
+
* **Chef Client** - command line tool for interacting with Chef Server.
|
71
|
+
* **Chef Solo** - you can run cookbooks in the absence of a Chef Server on single node.
|
72
|
+
You need to have cookbooks somewhere. <span style="color:red">Only Chef Solo will be used in this presentation</span>.
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
!SLIDE title-and-content transition=cover
|
77
|
+
|
78
|
+
# Common conceps of Chef
|
79
|
+
|
80
|
+
* **Node** - A host where the Chef client will be executed.
|
81
|
+
|
82
|
+
* **Recipe** - ruby program with code to install or configure software
|
83
|
+
(install webserver or database, create database user etc.).
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
# cookbooks/application/default.rb
|
87
|
+
|
88
|
+
include_recipe "rvm" # include another recipe
|
89
|
+
|
90
|
+
package "rvm" # include OS package
|
91
|
+
|
92
|
+
bash "ls -al" # run OS command
|
93
|
+
```
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
!SLIDE title-and-content transition=cover
|
98
|
+
|
99
|
+
# Common concepts of Chef (continued)
|
100
|
+
|
101
|
+
* **Cookbook** - a collection of recipes (e.g. db cookbook could handle common interface for
|
102
|
+
installing/configuring mysql and postgresql).
|
103
|
+
|
104
|
+
```
|
105
|
+
-cookbooks
|
106
|
+
-application
|
107
|
+
-attributes
|
108
|
+
default.rb
|
109
|
+
-recipes
|
110
|
+
default.rb
|
111
|
+
my_postgres.rb
|
112
|
+
my_mysql.rb
|
113
|
+
-templates
|
114
|
+
Gemfile.erb
|
115
|
+
mysql_database.yml.erb
|
116
|
+
```
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
!SLIDE title-and-content transition=cover
|
121
|
+
|
122
|
+
# Common concepts of Chef (continued)
|
123
|
+
|
124
|
+
* **Attribute** - default values to be used by cookbook in order to configure it (e.g. required
|
125
|
+
version, service port or user name/password etc.). They can be redefined when you configure recipe.
|
126
|
+
|
127
|
+
* **Data Bags** - collection of properties that can be used together.
|
128
|
+
|
129
|
+
* **Metadata** - describes the recipes, dependencies, supported platforms, etc.
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
!SLIDE title-and-content transition=cover
|
134
|
+
|
135
|
+
# Common concepts of Chef (continued)
|
136
|
+
|
137
|
+
* **Resource** - it could be file, directory, package, service etc.
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
directory "/var/cache/local/preseeding" do
|
141
|
+
owner "root"
|
142
|
+
group node['mysql']['root_group']
|
143
|
+
mode 0755
|
144
|
+
recursive true
|
145
|
+
end
|
146
|
+
service "mysql" do
|
147
|
+
action :start
|
148
|
+
end
|
149
|
+
dmg_package "GitOSX-Installer" do
|
150
|
+
type "pkg"
|
151
|
+
action :install
|
152
|
+
end
|
153
|
+
cron "noop" do
|
154
|
+
hour "5"
|
155
|
+
minute "0"
|
156
|
+
command "/bin/true"
|
157
|
+
end
|
158
|
+
```
|
159
|
+
|
160
|
+
|
161
|
+
!SLIDE title-and-content transition=cover
|
162
|
+
|
163
|
+
# Common concepts of Chef (continued)
|
164
|
+
|
165
|
+
* **Template** - powered by ERB and used for generation configuration files.
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
template "#{node[:rails][:app_root]}/Gemfile" do
|
169
|
+
source "Gemfile.erb"
|
170
|
+
mode "0666"
|
171
|
+
owner node[:rails][:user]
|
172
|
+
group node[:rails][:group]
|
173
|
+
variables({ :db_gem => "mysql" })
|
174
|
+
not_if { `ls #{node[:rails][:app_root]}`.include?("Gemfile") }
|
175
|
+
end
|
176
|
+
```
|
177
|
+
|
178
|
+
* **Role** - reusable configuration for multiple nodes (mac user role, web role, database role, etc).
|
179
|
+
|
180
|
+
* **Run List** - list of recipes and roles to run.
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
!SLIDE title-and-content transition=cover
|
185
|
+
|
186
|
+
# Running
|
187
|
+
|
188
|
+
* You create **recipes run list** in order to run provision.
|
189
|
+
|
190
|
+
```yml
|
191
|
+
{
|
192
|
+
"run_list": [ "recipe[application]" ]
|
193
|
+
}
|
194
|
+
```
|
195
|
+
|
196
|
+
* Chef runs a bunch of recipes to set up your server.
|
197
|
+
|
198
|
+
* You can run it with vagrant:
|
199
|
+
|
200
|
+
```bash
|
201
|
+
vagrant provision
|
202
|
+
vagrant reload
|
203
|
+
vagrant up
|
204
|
+
```
|
205
|
+
|
206
|
+
* or with chef-solo:
|
207
|
+
|
208
|
+
```bash
|
209
|
+
chef-solo -c your-solo-config-location.rb
|
210
|
+
-j your-solo-node-location.json
|
211
|
+
```
|
212
|
+
|
213
|
+
|
214
|
+
!SLIDE title-and-content transition=cover
|
215
|
+
|
216
|
+
# Example of configuration file
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
project_root = File.dirname(File.expand_path(__FILE__))
|
220
|
+
|
221
|
+
cookbook_path [File.join(project_root, "..", "cookbooks"),
|
222
|
+
File.join(project_root, "..", "vendored_cookbooks")]
|
223
|
+
|
224
|
+
#json_attribs File.join(project_root, "..", "nodes",
|
225
|
+
# "vagrant-node.json")
|
226
|
+
```
|
227
|
+
|
228
|
+
|
229
|
+
!SLIDE title-and-content transition=cover
|
230
|
+
|
231
|
+
# Example of vagrant-node.json file
|
232
|
+
|
233
|
+
```json
|
234
|
+
{
|
235
|
+
"run_list": [ "recipe[application]" ],
|
236
|
+
|
237
|
+
"application": { "app_name": "triton" },
|
238
|
+
|
239
|
+
"rvm": {"ruby": {"version": "1.9.3",
|
240
|
+
"implementation": "ruby",
|
241
|
+
"patch_level": "p392"}},
|
242
|
+
|
243
|
+
"postgresql": { "username": "postgres", "password": "postgres"},
|
244
|
+
|
245
|
+
"mysql": { "server_debian_password": "root",
|
246
|
+
"server_root_password": "root",
|
247
|
+
"server_repl_password": "root"}
|
248
|
+
}
|
249
|
+
```
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
!SLIDE title-and-content transition=cover
|
254
|
+
|
255
|
+
# Chef-Solo: Standalone Installation
|
256
|
+
|
257
|
+
* If you want to use chef apart from vagrant, you have to install chef gem:
|
258
|
+
|
259
|
+
```bash
|
260
|
+
gem install chef
|
261
|
+
```
|
262
|
+
|
263
|
+
* and then use it:
|
264
|
+
|
265
|
+
```bash
|
266
|
+
ssh user@your_server
|
267
|
+
cd
|
268
|
+
sudo chef-solo -c /vagrant/config/solo.rb -c /vagrant/nodes/node.rb
|
269
|
+
```
|
270
|
+
|
271
|
+
* <div style="color:red">Important: do it from user home.</div>
|
272
|
+
|
273
|
+
|
274
|
+
!SLIDE title-and-content transition=cover
|
275
|
+
|
276
|
+
# Common recipes
|
277
|
+
|
278
|
+
* Public cookbooks are located at [opscode community home](http://community.opscode.com/cookbooks)
|
279
|
+
|
280
|
+
* For easy manipulation with common recipes, install **librarian-chef** gem:
|
281
|
+
|
282
|
+
```bash
|
283
|
+
gem install librarian-chef
|
284
|
+
```
|
285
|
+
|
286
|
+
* Initialize librarian-chef. New **Cheffile** file will be created:
|
287
|
+
|
288
|
+
```bash
|
289
|
+
librarian-chef init
|
290
|
+
```
|
291
|
+
|
292
|
+
* Install cookbooks defined in Cheffile:
|
293
|
+
|
294
|
+
```bash
|
295
|
+
librarian-chef install --path vendored_cookbooks
|
296
|
+
```
|
297
|
+
|
298
|
+
* We keep them separately from our cookbooks. Our cookbooks are located in **cookbooks** folder.
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
!SLIDE title-and-content transition=cover
|
303
|
+
|
304
|
+
# Example of Cheffile
|
305
|
+
|
306
|
+
```ruby
|
307
|
+
site 'http://community.opscode.com/api/v1'
|
308
|
+
|
309
|
+
cookbook 'apt'
|
310
|
+
cookbook 'git'
|
311
|
+
|
312
|
+
cookbook 'mysql'
|
313
|
+
cookbook 'postgresql'
|
314
|
+
```
|
315
|
+
|
316
|
+
* Other useful commands:
|
317
|
+
|
318
|
+
```bash
|
319
|
+
librarian-chef outdated
|
320
|
+
librarian-chef update
|
321
|
+
```
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
!SLIDE title-and-content transition=cover
|
326
|
+
|
327
|
+
# Tip 1: Skipping consecutive runs
|
328
|
+
|
329
|
+
* If you run it several times, Chef can skip all consecutive runs, thanks to **not_if** method call:
|
330
|
+
|
331
|
+
```ruby
|
332
|
+
app_user = 'app_user'
|
333
|
+
postgres_user = 'postgres'
|
334
|
+
db_schema = 'myapp_dev'
|
335
|
+
|
336
|
+
bash "Creating postgres db user" do
|
337
|
+
user "postgres"
|
338
|
+
|
339
|
+
code <<-CODE
|
340
|
+
psql -c "CREATE USER #{app_user} WITH PASSWORD '#{app_user}'"
|
341
|
+
CODE
|
342
|
+
|
343
|
+
not_if { `sudo sudo -u #{postgres_user} psql -c '\\l'`.
|
344
|
+
include?(db_schema) }
|
345
|
+
end
|
346
|
+
```
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
!SLIDE title-and-content transition=cover
|
351
|
+
|
352
|
+
# Tip 2: Support for multiple platforms
|
353
|
+
|
354
|
+
* You can to different actions for different patforms if you want:
|
355
|
+
|
356
|
+
```ruby
|
357
|
+
# cookbooks/some_recipe/recipes/default.rb
|
358
|
+
|
359
|
+
case node[:platform]
|
360
|
+
when "ubuntu"
|
361
|
+
package "package_for_ubuntu"
|
362
|
+
when "centos"
|
363
|
+
package "package_for_centos"
|
364
|
+
when "mac_os_x"
|
365
|
+
package "package_for_mac_os_x"
|
366
|
+
end
|
367
|
+
```
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
!SLIDE title-and-content transition=cover
|
372
|
+
|
373
|
+
# Tip 3: Integration with Capistrano
|
374
|
+
|
375
|
+
* Capistrano **Capfile** script
|
376
|
+
|
377
|
+
```ruby
|
378
|
+
set :application, "vagrant"
|
379
|
+
set :host, "22.22.22.22"
|
380
|
+
set :user, "vagrant"
|
381
|
+
set :password, "vagrant"
|
382
|
+
role :vagrant, host
|
383
|
+
|
384
|
+
namespace :vagrant do
|
385
|
+
|
386
|
+
desc "Execute chef run_list"
|
387
|
+
task :run_list, :roles => :vagrant do
|
388
|
+
cmd = "/opt/vagrant_ruby/bin/chef-solo -c /vagrant/config/solo.rb
|
389
|
+
-j /vagrant/nodes/vagrant-node.json"
|
390
|
+
|
391
|
+
run %[sudo #{cmd}]
|
392
|
+
end
|
393
|
+
end
|
394
|
+
```
|
395
|
+
|
396
|
+
* Now you can run this task:
|
397
|
+
|
398
|
+
```bash
|
399
|
+
cap vagrant:run_list
|
400
|
+
```
|
@@ -0,0 +1,208 @@
|
|
1
|
+
!SLIDE
|
2
|
+
|
3
|
+
## What is it?
|
4
|
+
|
5
|
+
* "open source project to pack, ship and run any application as a lightweight container”.
|
6
|
+
|
7
|
+
* it works much like a virtual machine, wraps everything (filesystem, process management, environment variables, etc.)
|
8
|
+
into a container.
|
9
|
+
|
10
|
+
* Unlike a VM, it uses LXC (Linux kernel container) instead of a hypervisor.
|
11
|
+
|
12
|
+
* LXC doesn’t have its own kernel, but shares the Linux kernel with the host and other containers instead. Based on LXC,
|
13
|
+
Docker is so lightweight, that it introduces almost no performance drawback while running the application.
|
14
|
+
|
15
|
+
* provides a smart way to manage your images. Through Dockerfile and its caching mechanism, one can easily redeploy
|
16
|
+
an updated image without transferring large amounts of data.
|
17
|
+
|
18
|
+
|
19
|
+
## When it make sense to use?
|
20
|
+
|
21
|
+
* With VM You have to upload the whole new image even if you just made a small update. With Docker
|
22
|
+
you don’t have to upload the whole image again. Docker is based on AuFS, which tracks the diff of the whole filesystem.
|
23
|
+
|
24
|
+
* There is a significant performance loss. With Docker The performance loss is ignorable since it runs on the host kernel.
|
25
|
+
|
26
|
+
* Your probably run your application on a VPS, which is already a virtualized environment.
|
27
|
+
You can’t run a VM on top of another. You can run Docker on a VM because Docker is not a VM
|
28
|
+
|
29
|
+
## How it works?
|
30
|
+
|
31
|
+
* Docker needs to be run with root privelege.
|
32
|
+
|
33
|
+
Docker DOESN’T write into the image. Instead, it creates a layer with each Dockerfile line on top of the existing image,
|
34
|
+
which contains the modifications you made to the filesystem. Migrating from a previous state of filesystem to
|
35
|
+
a recent one is applying one or more layers on top of the old image, just like patching files.
|
36
|
+
|
37
|
+
When a container is stopped, you can commit it. Committing a container is creating an additional layer on top
|
38
|
+
of the base image. As expected, the official ubuntu image is also made up of several layers.
|
39
|
+
|
40
|
+
## What is Boot2Docker?
|
41
|
+
|
42
|
+
Boot2Docker is a lightweight Linux distribution made specifically to run Docker containers. It runs
|
43
|
+
completely from RAM, is a small ~24MB download and boots in ~5s (YMMV).
|
44
|
+
|
45
|
+
Installation instructions for OS X and Windows available on the Docker documentation site.
|
46
|
+
|
47
|
+
## How to use Boot2Docker
|
48
|
+
|
49
|
+
The boot2docker managment tool leverages VirtualBox's VBoxManage to initialise, start, stop and delete
|
50
|
+
the VM right from the command line.
|
51
|
+
|
52
|
+
# Initialize
|
53
|
+
|
54
|
+
$ boot2docker init
|
55
|
+
|
56
|
+
# Start VM
|
57
|
+
|
58
|
+
$ boot2docker up
|
59
|
+
|
60
|
+
# Upgrade the Boot2docker VM image
|
61
|
+
|
62
|
+
$ boot2docker stop
|
63
|
+
$ boot2docker download
|
64
|
+
$ boot2docker up
|
65
|
+
|
66
|
+
If your Boot2Docker virtual machine was created prior to 0.11.1-pre1, its best to delete -
|
67
|
+
boot2docker delete and then boot2docker init to create a new VM.
|
68
|
+
|
69
|
+
The main changes are to add a /var/lib/boot2docker/userdata.tar file that is un-tarred
|
70
|
+
into the /home/docker directory on boot. This file contains a .ssh/authorized_keys and .ssh/authorized_keys2
|
71
|
+
files containing a public sshkey.
|
72
|
+
|
73
|
+
## Installation
|
74
|
+
|
75
|
+
* Download and install VirtualBox for OSX
|
76
|
+
|
77
|
+
https://www.virtualbox.org/wiki/Downloads
|
78
|
+
|
79
|
+
* Install boot2docker and docker via homebrew:
|
80
|
+
|
81
|
+
```bash
|
82
|
+
brew install boot2docker
|
83
|
+
```
|
84
|
+
Docker will be installed as an dependency.
|
85
|
+
|
86
|
+
Initialize boot2docker virtual machine:
|
87
|
+
|
88
|
+
```bash
|
89
|
+
boot2docker init
|
90
|
+
```
|
91
|
+
|
92
|
+
Update .bash_profile file:
|
93
|
+
|
94
|
+
|
95
|
+
```bash
|
96
|
+
export DOCKER_HOST=tcp://192.168.59.103:2375
|
97
|
+
```
|
98
|
+
|
99
|
+
Start the docker daemon:
|
100
|
+
|
101
|
+
```bash
|
102
|
+
boot2docker up
|
103
|
+
```
|
104
|
+
|
105
|
+
or down:
|
106
|
+
|
107
|
+
```bash
|
108
|
+
boot2docker down
|
109
|
+
```
|
110
|
+
|
111
|
+
ssh it:
|
112
|
+
|
113
|
+
```bash
|
114
|
+
boot2docker ssh
|
115
|
+
|
116
|
+
# User: docker
|
117
|
+
# Pwd: tcuser
|
118
|
+
```
|
119
|
+
|
120
|
+
Download the small base image named busybox:
|
121
|
+
|
122
|
+
```bash
|
123
|
+
docker pull busybox
|
124
|
+
docker pull ubuntu
|
125
|
+
docker pull centos
|
126
|
+
```
|
127
|
+
|
128
|
+
Run and test as separate command:
|
129
|
+
|
130
|
+
```bash
|
131
|
+
docker run ubuntu /bin/echo hello world
|
132
|
+
```
|
133
|
+
|
134
|
+
and interactively:
|
135
|
+
|
136
|
+
|
137
|
+
```bash
|
138
|
+
docker run -t -i ubuntu /bin/bash
|
139
|
+
```
|
140
|
+
|
141
|
+
```bash
|
142
|
+
docker stop $(docker ps -a -q)
|
143
|
+
docker rm $(docker ps -a -q)
|
144
|
+
|
145
|
+
# Build containers from Dockerfiles
|
146
|
+
docker build -t postgres docker/postgres
|
147
|
+
docker build -t demo demo
|
148
|
+
|
149
|
+
# Run and link the containers
|
150
|
+
docker run -d -p 5432:5432 --name postgres postgres:latest
|
151
|
+
|
152
|
+
docker run --rm -p 42222:22 -p 9292:9292 -e POSTGRESQL_HOST='192.168.59.103' --name demo demo:latest /bin/bash -l -c "rackup"
|
153
|
+
|
154
|
+
--link postgres:db
|
155
|
+
|
156
|
+
docker run -d -p 9292:9292 --name demo demo:latest /bin/bash -l -c "rackup"
|
157
|
+
```
|
158
|
+
|
159
|
+
```bash
|
160
|
+
boot2docker ip # 192.168.59.103
|
161
|
+
|
162
|
+
open http://192.168.59.103
|
163
|
+
|
164
|
+
|
165
|
+
docker run --rm ubuntu env
|
166
|
+
|
167
|
+
docker port demo 22
|
168
|
+
|
169
|
+
ssh root@localhost -p 49153
|
170
|
+
|
171
|
+
VBoxManage modifyvm "boot2docker-vm" --natpf1 "containerssh,tcp,,42222,,42222"
|
172
|
+
|
173
|
+
```
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
-d means run in the background
|
178
|
+
|
179
|
+
--name xyz gives the container the friendly name xyz which we can use to refer to it later when we want to
|
180
|
+
stop it or link it to another container
|
181
|
+
|
182
|
+
-p 3000:3000 makes port 3000 from the container available as port 3000 on the host (the Virtualbox VM). Since we have Vagrant configured to forward port 3000 of the VM to your local machine 3000, you can access this container on port 3000 on your development machine as you would the normal Rails dev server (e.g. http://localhost:3000).
|
183
|
+
|
184
|
+
--link postgres:db establishes a link between the container you're starting (your Rails app) and the
|
185
|
+
Postgres container you started previously. This is in the format name:alias and will make ports exposed by the
|
186
|
+
Postgres container available to the Rails container.
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
!SLIDE
|
191
|
+
|
192
|
+
## Links
|
193
|
+
|
194
|
+
* Installing Docker on Mac OS X https://docs.docker.com/installation/mac/
|
195
|
+
* [Docker sources project = *https://github.com/dotcloud/docker*](https://github.com/dotcloud/docker)
|
196
|
+
* [Deploy Rails Applications Using Docker - *http://steveltn.me/blog/2014/03/15/deploy-rails-applications-using-docker*](http://steveltn.me/blog/2014/03/15/deploy-rails-applications-using-docker)
|
197
|
+
* [How to Skip Bundle Install When Deploying a Rails App to Docker if the Gemfile Hasn’t Changed - *http://ilikestuffblog.com/2014/01/06/how-to-skip-bundle-install-when-deploying-a-rails-app-to-docker*](http://ilikestuffblog.com/2014/01/06/how-to-skip-bundle-install-when-deploying-a-rails-app-to-docker)
|
198
|
+
|
199
|
+
|
200
|
+
http://www.talkingquickly.co.uk/2014/06/rails-development-environment-with-vagrant-and-docker
|
201
|
+
https://github.com/TalkingQuickly/docker_rails_dev_env/
|
202
|
+
https://coreos.com/docs/launching-containers/building/getting-started-with-docker
|
203
|
+
http://docs.docker.io/installation/binaries/#dockergroup
|
204
|
+
http://blog.gemnasium.com/post/65599561888/rails-meets-docker
|
205
|
+
https://github.com/gemnasium/rails-meets-docker
|
206
|
+
https://medium.com/@flawless_retard/a-osx-vagrant-docker-ruby-on-rails-setup-117daf4ef0a5
|
207
|
+
Docker Cheat Sheet - https://gist.github.com/wsargent/7049221
|
208
|
+
|