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,430 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-27T11:12:54.1233333+00:00

    HI Durga,

    1.

    Document you have given is not opening, please share me the working link

    2.

    Below highlighted indicates container path right ?

    User's image

    0 comments No comments

  2. Durga Reshma Malthi 4,430 Reputation points Microsoft External Staff Moderator
    2025-05-28T08:36:32.6066667+00:00

    Hi Diptesh Kumar

    As per discussion in private message,

    User's image

    Let me Clarify each one of your questions:

    Will software on D: be embedded into the image?

    1. No, the D: drive itself will not be embedded into the container image. If you're mounting D: as a volume (-v D:\agentdata:C:\persistent), the software installed on D: will reside on the host, not inside the container image.

    Will D: remain intact and usable when the image is deployed in Kubernetes (AKS)?

    1. Not automatically. Kubernetes doesn’t know about subst or drive letters
    2. When deploying to AKS, the container image itself will be immutable. Since D: is being mapped dynamically, it won't exist inside the Kubernetes pod unless explicitly configured. You will need to use persistent storage like PVC's - Persistent Volume Claims.

    Can this setup remain consistent across AKS deployments?

    1. Yes, but only if you use a Persistent Volume (PV).

    If the goal is to keep software installed on D: store it in an Azure Files share.

    For this Go to Azure Portal -> Create an Azure Storage Account -> Then Navigate to File Shares and Create it. Now, you’ll map D: inside your Windows container using the SMB protocol.

    Inside Storage Account, go to Access Keys and copy the key and then go to your File Share and Connect via SMB. Copy the provided net use command.

    Now Inside the Windows container, run:

    net use D: \\mywindowsagentstorage.file.core.windows.net\persistent-agent-share /user:mywindowsagentstorage xxxxxxxxxxxx==
    

    This mounts D: inside the container and persists software installed there.

    In AKS, ensure the drive remains consistent. Define PersistentVolume

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: azure-file-pv
    spec:
      capacity:
        storage: 100Gi
      accessModes:
        - ReadWriteMany
      azureFile:
        secretName: azure-secret
        shareName: persistent-agent-share
        storageAccountName: mywindowsagentstorage #your storage account name
    

    In your Kubernetes manifest, Create PVC:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: azure-file-pvc
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 100Gi
      volumeName: azure-file-pv
    

    Mount it inside the pod:

    containers:
      - name: windows-agent-container
        image: my-agent-image
        volumeMounts:
          - name: azure-storage
            mountPath: /persistent
    volumes:
      - name: azure-storage
        persistentVolumeClaim:
          claimName: azure-file-pvc
    

    Inside the container, run: subst D: C:\persistent

    This ensures D: drive remains accessible.

    Another approach you can try to use an init container in Kubernetes to restore the D: drive mapping before the main workload runs.

    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 the token of appreciation. Thank You.

    0 comments No comments

  3. Shyam Kumar 846 Reputation points
    2025-05-28T12:20:45.95+00:00

    Hi Durga,

    you mean both the steps, should be done one is creating file in storage account and using same file share in AKS? to have persistent storage for PODS(Agents ), am i right?

    0 comments No comments

  4. Durga Reshma Malthi 4,430 Reputation points Microsoft External Staff Moderator
    2025-05-29T08:30:23.46+00:00

    Hi Diptesh Kumar

    Yes, to ensure persistent storage for your Windows container agents running in AKS, you need to follow both steps.

    Feel free to reach out if you have any further queries.

    If you found the information helpful, please click "Upvote" on the post to let us know and consider accepting the answer as the 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.