Hi tarun k
To create a D drive for Docker Windows containers that will eventually be used inside a Kubernetes Pod as a self-hosted Azure DevOps agent, please follow the below steps:
Create D Drive on Windows Host:
- Open Disk Management -> Win + R -> type diskmgmt.msc -> Action -> Create VHD -> Set a location (e.g.,
C:\DockerData.vhdx
), Set size (e.g., 100GB) and choose VHDX format and Dynamically Expanding type. - Right-click the newly created disk -> Initialize and create a new simple volume and assign drive letter D. Now you have a D: drive available for Docker.
Configure Docker to Use D: for Windows Containers:
- Stop Docker (if running):
Stop-Service docker
- Move Docker data directory to D, by default, Docker uses
C:\ProgramData\Docker
. You can reconfigure Docker to store images/containers onD:
mkdir D:\DockerData move "C:\ProgramData\Docker" "D:\DockerData"
- Create or edit
C:\ProgramData\Docker\config\daemon.json
:{ "data-root": "D:\\DockerData" }
- Restart Docker by running:
Start-Service docker
Containerize the Self-Hosted Azure DevOps Agent (Windows):
Once Docker is set up to use D:
, you can build your Windows-based self-hosted agent container.
Example Dockerfile (Windows):
FROM mcr.microsoft.com/windows/servercore:ltsc2022
# Add tools and agent files
SHELL ["powershell", "-Command"]
RUN Invoke-WebRequest -Uri https://vstsagentpackage.azureedge.net/agent/3.236.0/vsts-agent-win-x64-3.236.0.zip -OutFile agent.zip; \
Expand-Archive agent.zip -DestinationPath C:\azagent; \
Remove-Item agent.zip
WORKDIR C:\azagent
# Entry script for agent
COPY start.ps1 .
CMD ["powershell.exe", "C:\\azagent\\start.ps1"]
#start.ps1 script:
$env:AZP_URL = "https://dev.azure.com/<org>"
$env:AZP_TOKEN = "<PAT>"
$env:AZP_AGENT_NAME = "docker-agent"
$env:AZP_POOL = "docker-pool"
.\config.cmd --unattended --url $env:AZP_URL --auth pat --token $env:AZP_TOKEN --pool $env:AZP_POOL --agent $env:AZP_AGENT_NAME --acceptTeeEula --runAsService
.\run.cmd
Later, if you're planning to deploy this Docker image as a Kubernetes Pod (e.g., in AKS),
- Create PVC:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: docker-agent-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 50Gi
- Deployment YAML Example:
apiVersion: apps/v1 kind: Deployment metadata: name: docker-agent spec: replicas: 1 selector: matchLabels: app: docker-agent template: metadata: labels: app: docker-agent spec: containers: - name: agent image: <your-container-registry>/windows-docker-agent:latest volumeMounts: - name: docker-volume mountPath: /azagent volumes: - name: docker-volume persistentVolumeClaim: claimName: docker-agent-pvc
Additional References:
Hope this helps!
Please Let me know if you have any queries.