Way of Creating D drive inside windows container agent in azure devops

Shyam Kumar 846 Reputation points
2025-05-26T11:07:27.5133333+00:00

Please suggest a way to create D drive in the windows container agent.

I am following answer from below but not clear

https://forums.docker.com/t/way-to-create-d-drive-in-windows-container/148273

Azure DevOps
0 comments No comments
{count} votes

Accepted answer
  1. Durga Reshma Malthi 4,165 Reputation points Microsoft External Staff Moderator
    2025-05-26T11:26:52.3+00:00

    Hi Diptesh Kumar

    Creating a D drive inside a Windows container agent in Azure DevOps isn't straightforward because containers usually operate with a single root filesystem (C:). However, you can achieve similar functionality using volume mounts or virtual drives.

    Here are some methods:

    1. You can mount an additional volume to simulate a D: drive:
         docker run -v D:\data:C:\mnt --name my-agent windows-container-image
      
      This maps D:\data from the host to C:\mnt inside the container.
    2. Or you can create a virtual drive inside the container using subst: This makes C:\mnt appear as D: inside the container.
         subst D: C:\mnt
      

    Hope this helps!

    Please Let me know if you have any queries.

    1 person found this answer helpful.
    0 comments No comments

8 additional answers

Sort by: Most helpful
  1. Shyam Kumar 846 Reputation points
    2025-05-26T11:30:27.53+00:00

    What if container dies? how to preserve D drive always and consistently?

    0 comments No comments

  2. Durga Reshma Malthi 4,165 Reputation points Microsoft External Staff Moderator
    2025-05-26T11:57:51.1833333+00:00

    Hi Diptesh Kumar

    To ensure persistent storage, you can try the below methods:

    1. You can mount a directory from the host machine into the container; this ensures that data persists outside the container lifecycle.
         docker run -v D:\data:C:\mnt --name my-agent windows-container-image
      
    2. You can attach a persistent data disk to your container host and mount it inside the container. Navigate to Azure Portal -> Create a Managed Disk in Azure and Attach it to the VM hosting your container. Format and mount it as D: inside the container. You can refer these docs: Attach Managed disk and Configure additional storage
    3. If you're using self-hosted agents, map a host folder to a fixed path in your container using docker run or your deployment tool:
         docker run -v D:\agentdata:C:\persistent your-image
      
      Then inside the container, run:
         subst D: C:\persistent
      
      This way, the container always sees D: and it maps to the host's D:\agentdata, which is persistent.

    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.


  3. Shyam Kumar 846 Reputation points
    2025-05-27T09:30:56.19+00:00

    Hi Durga,

    Please clarify my follow up questions:

    1.

    since I am using container as self hosted agent: I will use option 3, is that okay?

    2.

    so I am trying to use option 3 from your suggestions:

    here docker run -v D:\agentdata:C:\persistent your-image in this command, both agentdata on host and persistent both folders should be already there before executing this command?

    3.

    Why we execute this command?

    subst D: C:\persistent

    4.

    so can you give me document you used for suggesting step 3

    0 comments No comments

  4. Durga Reshma Malthi 4,165 Reputation points Microsoft External Staff Moderator
    2025-05-27T11:06:51.1266667+00:00

    Hi Diptesh Kumar

    Let me clarify for your above questions:

    1. 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.
    2. 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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.