Hi Diptesh Kumar
Let me clarify for your above questions:
- Yes, On the host machine (D:\agentdata): this folder should exist before running docker run, otherwise the container won't be able to mount it. Inside the container (C:\persistent): It will be created if it doesn’t exist. Docker automatically creates the target mount point in the container when it binds the volume.
- Since Windows containers don't allow direct drive letter mapping like bare-metal Windows systems, this command: subst D: C:\persistent, Here the subst command acts as a workaround to simulate a D: drive inside the container. Refer this doc: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/subst
You can also use Docker volumes, which remain intact even if the container dies:
Create Docker volume using cmd - docker volume create my_volume
When you run your container, mount the volume to the desired path - docker run -it -v my_volume:D:\MyData mcr.microsoft.com/windows/servercore:ltsc2019 powershell
Any data written to D:\MyData will be stored in the Docker volume and will persist even if the container is stopped or removed.
(or)
docker volume create myvolume
docker run -d --name mycontainer `
--mount source=myvolume,target=D: `
mcr.microsoft.com/windows/servercore:ltsc2022
This ensures myvolume exists outside the container, so even if the container is deleted, the data remains.
Hope this helps!
Please Let me know if you have any queries.
If you found the information helpful, please click "Upvote" on the post to let us know and consider accepting the answer as a token of appreciation. Thank You.