Commit 1d99280d authored by Michael Prieto Hernández's avatar Michael Prieto Hernández 👽
Browse files

remove container if already present

parent 8adef0a8
......@@ -5,19 +5,32 @@ import sys
class ContainerRun(Action):
def __init__(self, config=None):
super(ContainerRun, self).__init__(config=config)
self.client = docker.from_env()
def run(self, image=None, command=None, parameters=None):
"""
Run container
"""
try:
client = docker.from_env()
#print("image:" + image + ", command: " +
# command+", parameters:"+parameters)
jparameters = json.loads(parameters)
jparameters["detach"] = True
jparameters["remove"] = True
client.containers.run(image, command, **jparameters)
container_name = jparameters["name"]
if(container_name):
for container in self.client.containers.list():
if(container.name==container_name):
container.remove(force=True)
self.client.containers.run(image, command, **jparameters)
except Exception as e:
print(e)
sys.exit(1)
def remove_container(self, name=None):
for container in self.client.containers.list():
if(container.name==name):
container.remove(force=True)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment