I have created a react app to start/reset docker some containers. I do this with reactstrap, shelljs and express.
Now I also want to get feedback like if those containers currently starting, if its up or if it's removed/not existing.
I think one way to get the status of existing containers would be by starting them not as a daemon like this:
app.post('/api', (req, res) => {
console.log(req.body);
const action = req.body.action;
const service = req.body.service;
switch (action) {
case "start":
var container = sh.exec(docker-compose up -d "+ service, {async:true});
return container;
}
I would detect non-existent containers if there is no data stream.
Maybe I can return the container object as like above and constantly check its data in the app: container.stdout.on('data', function(data)
As I'm new to this. I'm not quite sure if I'm going the right way and how to work with that data stream. Maybe filtering it in a variable which could be printed in the apps UI.
And it seems like as if I need some kind of dynamic variable name for the container object by adding the service name.
EDIT: Another solution would be sending every some seconds a docker ps and parse the data. Doing as long as the page in browser is active.