0004
0004

Reputation: 1260

Start Docker with python subprocess for a command line utility

I confused as to why the following code returns an error:

import subprocess

a = subprocess.Popen(["docker-compose down weather-data"])
a.wait()

I get as an error:

FileNotFoundError: [Errno 2] No such file or directory: 'docker-compose down weather-data'

Upvotes: 0

Views: 462

Answers (1)

sidprak
sidprak

Reputation: 136

Your command needs to be in an array with each part of the command as one element in the array. For example:

import subprocess
a = subprocess.Popen(["docker-compose", "down", "weather-data"])
a.wait()

If it's all in one string, Python is trying to find a single executable named "docker-compose down weather-data".

Upvotes: 2

Related Questions