Differentiate between creating a fresh container and recreating an already existing one.
This commit is contained in:
parent
33a8df5ac1
commit
1ee6de03c1
14
dup.rb
14
dup.rb
@ -120,14 +120,16 @@ def action_help
|
|||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run_cmd(cmd, ignore_returnvalue=false, catch_interrupt=false, ignore_dry_run: false)
|
||||||
verbose "+ #{cmd}"
|
verbose "+ #{cmd}"
|
||||||
returnvalue=false
|
returnvalue=false
|
||||||
begin
|
begin
|
||||||
returnvalue = $dry_run ? true : system("bash -c #{cmd.shellescape}")
|
returnvalue = ($dry_run && !ignore_dry_run) ? true : system("bash -c #{cmd.shellescape}")
|
||||||
rescue Interrupt
|
rescue Interrupt
|
||||||
raise if not catch_interrupt
|
raise if not catch_interrupt
|
||||||
end
|
end
|
||||||
raise "Command returned a non-zero exit value." if returnvalue!=true && !ignore_returnvalue
|
raise "Command returned a non-zero exit value." if returnvalue!=true && !ignore_returnvalue
|
||||||
|
return returnvalue
|
||||||
end
|
end
|
||||||
|
|
||||||
def esc(obj, escape=true)
|
def esc(obj, escape=true)
|
||||||
@ -203,6 +205,10 @@ class Container
|
|||||||
@name = name
|
@name = name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def exists?
|
||||||
|
run_cmd("docker inspect --format='1' #{@name.shellescape} >/dev/null 2>&1", true, ignore_dry_run: true)
|
||||||
|
end
|
||||||
|
|
||||||
def load
|
def load
|
||||||
raise "File #{self.filename} not found." unless File.exists?(self.filename)
|
raise "File #{self.filename} not found." unless File.exists?(self.filename)
|
||||||
|
|
||||||
@ -333,6 +339,12 @@ class Container
|
|||||||
self.pull
|
self.pull
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.exists?
|
||||||
|
puts "Recreating #{@name}..."
|
||||||
|
else
|
||||||
|
puts "Creating #{@name}..."
|
||||||
|
end
|
||||||
|
|
||||||
self.stop_and_remove
|
self.stop_and_remove
|
||||||
|
|
||||||
self.create_networks
|
self.create_networks
|
||||||
|
Loading…
Reference in New Issue
Block a user