-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcontainer_with_volume.rb
42 lines (35 loc) · 1.71 KB
/
container_with_volume.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'spec_helper'
# Note: we're using a mounted volume located within the host vm, because if we would mount something from OS X, we would have write permission problems: https://github.com/boot2docker/boot2docker/issues/581
describe "running a container with mounted volume" do
before :all do
`boot2docker ssh "if [ -d /tmp/empty-data-dir ]; then sudo rm -rf /tmp/empty-data-dir; fi; mkdir /tmp/empty-data-dir"`
@container = Docker::Container.create(
'Image' => IMAGE_TAG,
'Detach' => true,
'Env' => [ 'MYSQL_ROOT_PASSWORD=foo' ]
)
@container.start('Binds' => '/tmp/empty-data-dir:/var/lib/mysql')
# Wait for mysql to start
@container.exec(['bash', '-c', 'mysqladmin --silent --wait=30 ping'])
end
it "can run mysql query through build in mysql client" do
stdout, stderr = @container.exec(['bash', '-c', 'mysql -e "show databases;"'])
expect(stderr.first).to_not match(/Access denied for user/)
expect(stdout.first).to match(/mysql/)
expect(stdout.first).to match(/information_schema/)
expect(stdout.first).to_not match(/test/)
expect(stdout.first).to_not match(/survive/)
end
# the following also tests the case where we mount an already existing data dir
it "can be stopped, started again and data survives" do
@container.exec(['bash', '-c', 'mysql -e "create database survive;"'])
@container.restart
@container.exec(['bash', '-c', 'mysqladmin --silent --wait=30 ping'])
stdout, stderr = @container.exec(['bash', '-c', 'mysql -e "show databases;"'])
expect(stdout.first).to match(/survive/)
end
after :all do
@container.delete(force: true, v: true)
`boot2docker ssh "sudo rm -rf /tmp/empty-data-dir"`
end
end