Commit 010abfc8 by chalermpong

add pull image and fix start-stop

parent 0e5d6fa0
{
"services": [
{
"image": "testcontainers/helloworld",
"restart": "always",
"name": "my_hello_world_container",
"ports": [
{ "containerPort": "8080", "hostPort": "9080" }
],
"volumes": [
{
"source": "/home/bakukan2008/npm",
"target": "/usr/src/app"
},
{
"source": "/var/run/docker.sock",
"target": "/var/run/docker.sock"
}
],
"environment": [
{
"key": "ENV_KEY1",
"value": "ENV_VALUE1"
},
{
"key": "ENV_KEY2",
"value": "ENV_VALUE2"
}
],
"network": "bridge",
"logging": {
"Config": {
"max-size": "10m",
"max-file": "3"
},
"Type": "json-file"
}
},
{
"image": "2e8d6130b913",
"restart": "always",
"name": "myflowengine",
"ports": [
{ "containerPort": "80", "hostPort": "41880" },
{ "containerPort": "1883", "hostPort": "4080" }
],
"volumes": [
{
"source": "/mongo/data",
"target": "/data/db"
}
],
"environment": [
{
"key": "MONGO_INITDB_ROOT_USERNAME",
"value": "admin"
},
{
"key": "MONGO_INITDB_ROOT_PASSWORD",
"value": "admin_password"
}
],
"network": "flowstack",
"logging": {
"Config": {
"max-size": "10m",
"max-file": "3"
},
"Type": "json-file"
}
}
]
}
{
"serviceNames": ["2a2a514409d6", "my_hello_world_container"]
}
\ No newline at end of file
{
"services": [
{
"image": "testcontainers/helloworld",
"name": "my_hello_world_container",
"port": "8080",
"hostPort": "9080",
"volumes": [
{
"source": "/home/bakukan2008/npm",
"target": "/usr/src/app"
},
{
"source": "/var/run/docker.sock",
"target": "/var/run/docker.sock"
}
],
"envs": [
{
"key": "ENV_KEY1",
"value": "ENV_VALUE1"
},
{
"key": "ENV_KEY2",
"value": "ENV_VALUE2"
}
],
"network": "flowstack",
"logging": {
"Config": {
"max-size": "10m",
"max-file": "3"
},
"Type": "json-file"
}
},
{
"image": "2e8d6130b913",
"name": "flowengine",
"port": "80",
"hostPort": "41880",
"volumes": [
{
"source": "/flowtest/data",
"target": "/data/db"
}
],
"envs": [
{
"key": "ROOT_USERNAME",
"value": "admin"
},
{
"key": "ROOT_PASSWORD",
"value": "admin_password"
}
],
"network": "flowstack",
"logging": {
"Config": {
"max-size": "10m",
"max-file": "3"
},
"Type": "json-file"
}
}
]
}
const Docker = require('dockerode');
// var dockerCLI = require('docker-cli-js');
// var DockerOptions = dockerCLI.Options;
// var DockerCli = dockerCLI.Docker;
// สร้าง instance ของ Dockerode
const docker = new Docker();
// เรียกใช้งาน Docker API เพื่อดึงข้อมูลสถิติของ container ทั้งหมด
docker.listContainers((err, containers) => {
// var dockerCli = new DockerCli();
// const username = 'myusername';
// const password = 'mypassword';
// const loginCommand = `login -u ${username} -p ${password}`;
// // ทำการ login
// dockerCli.command(loginCommand).then(data => {
// console.log('Login สำเร็จ:', data);
// }).catch(err => {
// console.error('เกิดข้อผิดพลาดในการ login:', err);
// });
const Docker = require('dockerode');
const docker = new Docker();
docker.listImages((err, images) => {
if (err) {
console.error('Error:', err);
console.error('เกิดข้อผิดพลาดในการดึงรายการ Docker images:', err);
} else {
// วนลูปผ่าน container ทั้งหมด
containers.forEach((containerInfo) => {
const containerId = containerInfo.Id;
// ดึงข้อมูลสถิติของ container นั้น
docker.getContainer(containerId).stats((err, stream) => {
if (err) {
console.error('Error:', err);
console.log('รายการ Docker images ทั้งหมด:', images);
// ตรวจสอบว่า Docker image ที่ต้องการอยู่ใน Repository หรือไม่
const imageName = 'harbor.nexpie.com/flowstack/mongo-gui:1.0.0-4';
const imageExists = images.some(image => image.RepoTags.includes(imageName));
if (imageExists) {
console.log(`Docker image '${imageName}' อยู่ใน Repository`);
} else {
stream.on('data', (chunk) => {
const stats = JSON.parse(chunk.toString('utf8'));
// แสดงข้อมูล CPU และ Memory
console.log('Container:', containerInfo.Names[0]);
console.log('CPU Usage:', stats.cpu_stats.cpu_usage.cpu_percent);
console.log('Memory Usage:', stats.memory_stats.usage);
});
stream.on('error', (err) => {
console.error('Stream error:', err);
});
console.log(`Docker image '${imageName}' ไม่อยู่ใน Repository`);
}
});
});
}
});
});
\ No newline at end of file
......@@ -5,6 +5,9 @@
"packages": {
"": {
"dependencies": {
"body-parser": "^1.20.2",
"docker-cli-js": "^2.10.0",
"docker-modem": "^5.0.3",
"dockerode": "^4.0.2",
"dockerode-compose": "^1.4.0",
"express": "^4.19.2",
......@@ -18,6 +21,45 @@
"resolved": "https://registry.npmjs.org/@balena/dockerignore/-/dockerignore-1.0.2.tgz",
"integrity": "sha512-wMue2Sy4GAVTk6Ic4tJVcnfdau+gx2EnG7S+uAEe+TWJFqE4YoWN4/H8MSLj4eYJKxGg26lZwboEniNiNwZQ6Q=="
},
"node_modules/@types/blue-tape": {
"version": "0.1.36",
"resolved": "https://registry.npmjs.org/@types/blue-tape/-/blue-tape-0.1.36.tgz",
"integrity": "sha512-t2nyn0z6Q5PM/SA8suQEVfV1QsJ37XFlR7zEayviC/EdrqWq8JiKzE7BtwBcO28wFZ4bKQeD7MeJAj1B35KYAA==",
"dependencies": {
"@types/node": "*",
"@types/tape": "*"
}
},
"node_modules/@types/lodash": {
"version": "4.14.119",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.119.tgz",
"integrity": "sha512-Z3TNyBL8Vd/M9D9Ms2S3LmFq2sSMzahodD6rCS9V2N44HUMINb75jNkSuwAx7eo2ufqTdfOdtGQpNbieUjPQmw=="
},
"node_modules/@types/node": {
"version": "20.12.7",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz",
"integrity": "sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==",
"dependencies": {
"undici-types": "~5.26.4"
}
},
"node_modules/@types/tape": {
"version": "5.6.4",
"resolved": "https://registry.npmjs.org/@types/tape/-/tape-5.6.4.tgz",
"integrity": "sha512-EmL4fJpZyByNCkupLLcJhneqcnT+rQUG5fWKNCsZyBK1x7nUuDTwwEerc4biEMZgvSK2+FXr775aLeXhKXK4Yw==",
"dependencies": {
"@types/node": "*",
"@types/through": "*"
}
},
"node_modules/@types/through": {
"version": "0.0.33",
"resolved": "https://registry.npmjs.org/@types/through/-/through-0.0.33.tgz",
"integrity": "sha512-HsJ+z3QuETzP3cswwtzt2vEIiHBk/dCcHGhbmG5X3ecnwFD/lPrMpliGXxSCg03L9AhrdwA4Oz/qfspkDW+xGQ==",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/accepts": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
......@@ -222,6 +264,16 @@
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz",
"integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg=="
},
"node_modules/cli-table-2-json": {
"version": "1.0.13",
"resolved": "https://registry.npmjs.org/cli-table-2-json/-/cli-table-2-json-1.0.13.tgz",
"integrity": "sha512-CpUj9dubfuIZSEezwUPycAJqM2dlATyyRUyBkfGeK2KNfrqK3XrdaBohMt0XlkEvsZyDfUEmPWCNvUO+a/7Wsw==",
"dependencies": {
"@types/blue-tape": "^0.1.30",
"@types/lodash": "4.14.119",
"lodash": "^4.17.15"
}
},
"node_modules/content-disposition": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
......@@ -317,6 +369,17 @@
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/docker-cli-js": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/docker-cli-js/-/docker-cli-js-2.10.0.tgz",
"integrity": "sha512-p/Hf3igU69bIZ0WvHu0M0/VrKE3LojVWiKyh/4hfPkvCGaad3mWE51q0OyxYP+P26cEISAx0mImtsO6VJdKiZA==",
"dependencies": {
"cli-table-2-json": "1.0.13",
"dockermachine-cli-js": "3.0.5",
"lodash.snakecase": "^4.1.1",
"nodeify-ts": "1.0.6"
}
},
"node_modules/docker-modem": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/docker-modem/-/docker-modem-5.0.3.tgz",
......@@ -331,6 +394,15 @@
"node": ">= 8.0"
}
},
"node_modules/dockermachine-cli-js": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/dockermachine-cli-js/-/dockermachine-cli-js-3.0.5.tgz",
"integrity": "sha512-oV9RRKGvWrvsGl8JW9TWKpjBJVGxn/1qMvhqwPJiOPfRES0+lrq/Q8Wzixb6qinuXPVBhlWqhXb/Oxrh6Vuf/g==",
"dependencies": {
"cli-table-2-json": "1.0.13",
"nodeify-ts": "1.0.6"
}
},
"node_modules/dockerode": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/dockerode/-/dockerode-4.0.2.tgz",
......@@ -694,6 +766,16 @@
"js-yaml": "bin/js-yaml.js"
}
},
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"node_modules/lodash.snakecase": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz",
"integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw=="
},
"node_modules/media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
......@@ -769,6 +851,11 @@
"node": ">= 0.6"
}
},
"node_modules/nodeify-ts": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/nodeify-ts/-/nodeify-ts-1.0.6.tgz",
"integrity": "sha512-jq+8sqVG1aLqy5maMTceL8NUJ1CvarWztlxvrYh3G0aao9BsVeoVmVedUnrUSBLetP7oLIAJrPrw4+iIo7v3GA=="
},
"node_modules/object-inspect": {
"version": "1.13.1",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz",
......@@ -1114,6 +1201,11 @@
"node": ">= 0.6"
}
},
"node_modules/undici-types": {
"version": "5.26.5",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="
},
"node_modules/unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
......
{
"dependencies": {
"body-parser": "^1.20.2",
"docker-cli-js": "^2.10.0",
"docker-modem": "^5.0.3",
"dockerode": "^4.0.2",
"dockerode-compose": "^1.4.0",
"express": "^4.19.2",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment