。自動化測試,本地和構建服務器上,我試圖旋轉了一個副本集(我需要oplog)的蒙戈圖像自動化測試
複製集設置需要我進入mongo shell並調用「rs.initiate()」。我希望這一切都在代碼中完成。
public void SpinUpMongoWithReplicaSet()
{
Process.Start("docker", "run -p 123:27017 --name test_mongo -d mongo:latest mongod --replSet rs0").WaitForExit();
var replicaSetProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "docker",
Arguments = "exec -it test_mongo mongo",
UseShellExecute = false,
RedirectStandardInput = true
}
};
replicaSetProcess.Start();
using(StreamWriter writer = replicaSetProcess.StandardInput)
{
writer.WriteLine("rs.initiate()");
writer.WriteLine("exit");
}
replicaSetProcess.WaitForExit();
}
但是,docker exec命令的問題。
當傳遞-IT或只是-t,我得到以下錯誤:
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
我能找到的唯一的解決辦法是隻在-i標誌傳遞。無論出於何種原因,這則阻止我連接到蒙戈容器:
MongoDB shell version v3.4.9 connecting to: mongodb://127.0.0.1:27017 2017-10-06T18:25:06.765+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused 2017-10-06T18:25:06.765+0000 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed : [email protected]/mongo/shell/mongo.js:237:13 @(connect):1:6 exception: connect failed
有誰在C#代碼中執行的泊塢窗圖像的命令的經驗嗎?
參考:這是一個很好的指導建立與碼頭工人一蒙戈副本集服務器,而是從命令行。 Docker Replica Set Setup