0

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.

edass
  • 45
  • 7
  • If you're doing this you need to be very very very careful with security-related things: it's easy to use Docker commands to take over the host. In your example, what happens if I send a message body of `{"service": "; docker run --rm -v/:/host busybox cat /host/etc/shadow"}`? – David Maze Mar 29 '21 at 18:02
  • Yes. It's not for public use and also password restricted. I keep that in mind. Thank you. – edass Mar 29 '21 at 18:10

0 Answers0