-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker_recreate.js
More file actions
43 lines (35 loc) · 1.02 KB
/
docker_recreate.js
File metadata and controls
43 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { execSync } from 'child_process';
function run(cmd) {
try {
console.log(`Running: ${cmd}`);
execSync(cmd, { stdio: 'inherit' });
} catch (err) {
console.error(`Error running: ${cmd}`);
}
}
function getIds(cmd) {
try {
return execSync(cmd).toString().trim().split(/\r?\n/).filter(Boolean);
} catch {
return [];
}
}
// Stop all running containers
const runningContainers = getIds('docker ps -q');
if (runningContainers.length) {
run(`docker stop ${runningContainers.join(' ')}`);
}
// Remove all containers
const allContainers = getIds('docker ps -aq');
if (allContainers.length) {
run(`docker rm ${allContainers.join(' ')}`);
}
// Remove all volumes
const allVolumes = getIds('docker volume ls -q');
if (allVolumes.length) {
run(`docker volume rm ${allVolumes.join(' ')}`);
}
// Build the API service using the development environment variables
run('docker-compose --env-file .env.development build api');
// Start the API service
run('docker-compose --env-file .env.development up -d');