【发布时间】:2019-04-01 15:36:40
【问题描述】:
我有最基本的控制台应用程序,它将消息记录到容器中的某个位置。我只想将这些消息写入位于我的 docker 主机中的持久性卷。
容器 - windows 容器
操作系统 - 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 信息,一切正常。
P.S:所以,问题是我一开始提到Volume,容器就会启动然后退出。当我做docker {containerID} inspect 时,我可以看到
容器c:/data 已安装到我的卷文件夹中的物理位置。
问题:为什么我的容器启动然后立即退出。但是一旦我删除卷标签,它就会继续正常工作并循环并将消息写入容器内的MyTest.txt 文件。
【问题讨论】:
-
你在
docker logs看到了什么? -
您不能在 Dockerfile 中使用绝对路径。你到底想达到什么目的?
-
我希望将消息写入主机的卷中,在持久性存储中
-
那个
VOLUME指令不能这样做;除了COPY或ADD之外,Dockerfile 中没有任何内容引用主机。它会产生一些令人惊讶的副作用,我建议将其移除。 @Mihai 的答案没有它就可以正常工作。
标签: c# .net docker containers