lib/vocker/docker_client.rb in vocker-0.4.0 vs lib/vocker/docker_client.rb in vocker-0.4.1
- old
+ new
@@ -46,21 +46,21 @@
create_container(config)
end
end
def container_exist?(id)
- @machine.communicate.test("sudo docker ps -a -q | grep -q #{id}")
+ lookup_container(id, true)
end
def start_container(id)
unless container_running?(id)
@machine.communicate.sudo("docker start #{id}")
end
end
def container_running?(id)
- @machine.communicate.test("sudo docker ps -q | grep #{id}")
+ lookup_container(id)
end
def create_container(config)
# DISCUSS: Does this really belong here?
ensure_bind_mounts_exist(config)
@@ -94,9 +94,21 @@
args += Array(config[:volumes]).map { |volume| "-v #{volume}" }
args += Array(config[:ports]).map { |port| "-p #{port}" }
args += Array(config[:links]).map { |link| "-link #{link}" }
args.compact.flatten.join ' '
+ end
+
+ def lookup_container(id, list_all = false)
+ docker_ps = "sudo docker ps -q"
+ docker_ps << " -a" if list_all
+ @machine.communicate.tap do |comm|
+ # Docker < 0.7.0 stores container IDs using its short version while
+ # recent versions use the full container ID
+ # See https://github.com/dotcloud/docker/pull/2140 for more information
+ return comm.test("#{docker_ps} | grep -wFq #{id}") ||
+ comm.test("#{docker_ps} -notrunc | grep -wFq #{id}")
+ end
end
end
end
end