[英]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.