var express = require('express'); var router = express.Router(); var docker = require('../bin/dockerode'); const registry = 'registry.cliffbreak.de/'; router.get('/:id/:image', async (req, res, next) => { if (req.params.image = ! null) { await pullImage(req.params.image); restartContainer(req.params.id).then(data => { res.send(data); }); } else { restartContainer(req.params.id).then(data => { res.send(data); }); } }); function restartContainer(containername) { return new Promise((resolve, reject) => { const container = docker.getContainer(containername); container.restart((err, data) => { resolve({ err, data }); }); }) } function pullImage(image) { return new Promise((resolve, reject) => { docker.pull(registry + image, (err, stream) => { resolve({ err, stream }); }); }) } module.exports = router;