在docker container裡用child_process.execSync - Linux

Aaliyah avatar
By Aaliyah
at 2016-08-20T05:23

Table of Contents

請問各位我有一個docker container裡裝node跑一個小小的測試JS檔, 當我進入docker container跑都沒問題, 但是如果用docker exec的command卻會發生錯誤
我猜是在docker container外部執行無法取的子進程. 有人有任何經驗如何解決嗎
我在docker container裡測試的腳本和結果
root@17dbb03697b0:/apps# cat test.js
var aaa = require('child_process').execSync('echo "aaaaaaaaa"').toString().trim();
console.log(aaa);
root@17dbb03697b0:/apps# node test.js
aaaaaaaaa
root@17dbb03697b0:/apps#

在docker container外測試的結果
user@ip-172-1-1-121:~/$ docker exec containername bash -c "cd /apps/;cat test.js"
var aaa = require('child_process').execSync('echo "aaaaaaaaa"').toString().trim();
console.log(aaa);
user@ip-172-1-1-121:~/$ docker exec containername bash -c "cd /apps;node test.js"

/apps/test.js:1
module, __filename, __dirname) { var aaa = require('child_process').execSync('
^
TypeError: Object #<Object> has no method 'execSync'
at Object.<anonymous> (/apps/test.js:1:98)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3

--
Tags: Linux

All Comments

David avatar
By David
at 2016-08-24T10:36
nodejs 確認至少是 0.12 版本嗎?
Lauren avatar
By Lauren
at 2016-08-27T23:35
exec 時候改成傳列出版本參數看看
Jack avatar
By Jack
at 2016-09-01T08:48
感謝, 發現是我裝nvm node時路徑沒有map到/usr/bin/
Necoo avatar
By Necoo
at 2016-09-01T23:29
/usr/bin/node 加上soft link 後就可以了

shell script何控制外面?

William avatar
By William
at 2016-08-18T22:21
如題 shell script要如何對外面有作用 好比我這樣寫test.sh #!bin/sh cd .. cd .. cd .. 然後執行bash test.sh 沒有任何事情發生 -- 作者: fleece (...) 看板: KoreanPop 標題: [問題] 請問一個叫O.S.T的歌手 ...

Linux 或開源多人開發運作模式

Elvira avatar
By Elvira
at 2016-08-18T21:56
我們team是採用github flow 在production machine上的是stable版本,也就是master branch 而正在開發的新功能是在同個feature branch 平常開發大家都是commit到這個feature branch commit前會先pull最新的code解決 ...

新的 AMD 顯卡在 Ubuntu 16.04 上使用的問題

Hedwig avatar
By Hedwig
at 2016-08-18T15:16
最近查詢了一下網路上的資訊,據網友使用的經驗,AMD 在 Linux 上的開源驅動效能已經超越了自家的閉源驅動,雖然和 Nvidia 的 專利驅動相比可能還有一段差距,但聽起來真的是頗吸引人的,所 以想請教這邊有在用 AMD 顯卡的前輩們一些問題。 1. 撇除過去對於 AMD 不爽的想法,現在的 AMD 開 ...

筆電安裝opensuse 42.1問題

Necoo avatar
By Necoo
at 2016-08-18T14:10
新買一台筆電 Dell XPS 15 硬碟為PCIe SSD 想安裝Windows 10 和 opensuse 42.1雙系統 有把ssd raid改AHCI 及關掉 boot secure 但安裝了好幾次都到96%安裝boot那地方當機 後來連BIOS都找不到硬碟 連win 10 都進不去 最後不知怎樣試到 ...

字串比較問題求救

Connor avatar
By Connor
at 2016-08-17T21:45
版上大大大家好 小弟最近正在學習Linux中,但遇到了一個數值比對問題無法解決,懇請版上大大指點迷 津 game() { if [ -n and#39;echo ${_game_list} | grep -i and#34; POand#34;and#39; ]; then _game_id =PO ...