1

I need to run following command inside python script to remove all exisiting docker services

import subprocess
bashCommand = "docker service rm $(docker service ls)" 
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE,  shell=True)

This is not giving desired results. Services still exists after running this file. I am using centos

2 Answers 2

5

Have you tried you use subprocess.call instead?

For example,

import subprocess
subprocess.call("docker rmi $(docker ps -a -q)", shell=True)

it works for rmi command.

Sign up to request clarification or add additional context in comments.

Comments

0

Have a look at this library :

You could loop all services through services.list() and rm them with service.remove()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.