I have the most basic console application which logs messages to a location in container. I just want that messages to be written to a persistance volume located in my docker host.
Container - windows container
OS - Windows 10
Code:
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
Command Run:
docker build -t fridayimg1:1.0 .
docker run {ImageID}
Everything works fine if I do not give Volume
info in the DockerFile.
PS: So, the problem is as soon as I start mentioning Volume
the container starts and then exits. When I do docker {containerID} inspect
, I can see that the container c:/data
has been mounted to a physical location in my Volumes folder.
Question: Why my container starts and then exits immediately. But as soon as I remove the volume tag, it continues to work fine and loop and writes messages to MyTest.txt
file inside the container.
You need to map the volume when you run the container, not when you build it (in Dockerfile).
docker run -v ./data:/data <your image>
This will map a folder "data" in your current folder to the path "/data" in your container.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.