Merge pull request #2579 from mitchellh/2579-fix-docker-container-running-check
provisioners/docker: Check for whether the container is running is not working properly
This commit is contained in:
commit
1b847b7829
|
@ -44,15 +44,15 @@ module VagrantPlugins
|
|||
|
||||
id = "$(cat #{config[:cidfile]})"
|
||||
|
||||
if container_exist?(id)
|
||||
if container_exists?(id)
|
||||
start_container(id)
|
||||
else
|
||||
create_container(config)
|
||||
end
|
||||
end
|
||||
|
||||
def container_exist?(id)
|
||||
@machine.communicate.test("sudo docker ps -a -q | grep -q #{id}")
|
||||
def container_exists?(id)
|
||||
lookup_container(id, true)
|
||||
end
|
||||
|
||||
def start_container(id)
|
||||
|
@ -62,7 +62,7 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def container_running?(id)
|
||||
@machine.communicate.test("sudo docker ps -q | grep #{id}")
|
||||
lookup_container(id)
|
||||
end
|
||||
|
||||
def create_container(config)
|
||||
|
@ -73,6 +73,18 @@ module VagrantPlugins
|
|||
docker run #{args} #{config[:image]} #{config[:cmd]}
|
||||
]
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue