[英]Container starts and immediately stops when mounted to a volume
我有最基本的控制台應用程序,它將消息記錄到容器中的某個位置。 我只想將這些消息寫入我的docker主機中的持久卷。
容器 - 窗戶容器
操作系統 - Windows 10
碼:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("starting");
string path = @"c:\exe\MyTest.txt";
int i = 0;
while (true)
{
string createText = $" {i} + Hello and Welcome"+ Environment.NewLine;
File.AppendAllText(path, createText);
i++;
}
}
}
Dockerfile:
# getting base image
FROM microsoft/windowsservercore:latest
ADD ./bin/debug /exe/
VOLUME c:/data # this line creates issue
ENTRYPOINT ["/exe/BackendService.bat"]
BackendService.bat
start c:\exe\ConsoleApp16.exe
命令運行:
docker build -t fridayimg1:1.0 .
docker run {ImageID}
如果我不在DockerFile中提供Volume
信息,一切正常。
PS:所以,問題是我一開始提到Volume
容器啟動然后退出。 當我執行docker {containerID} inspect
,我可以看到容器c:/data
已經掛載到Volumes文件夾中的物理位置。
問題:為什么我的容器啟動然后立即退出。 但是一旦我刪除了卷標記,它就會繼續正常工作並循環並將消息寫入容器內的MyTest.txt
文件。
您需要在運行容器時映射卷,而不是在構建容器時映射卷(在Dockerfile中)。
docker run -v ./data:/data <your image>
這會將當前文件夾中的文件夾“data”映射到容器中的路徑“/ data”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.