- 1 year ago
Accessing TFS (on prem) via powershell in docker windows container
To access Team Foundation Server (TFS) on-premises from a PowerShell script running inside a Windows Docker container, you need to ensure that the container has the necessary network access to reach the TFS server.
Here are the steps you can follow to set up PowerShell inside a Windows Docker container and access TFS:
Install Docker Desktop: Ensure you have Docker Desktop installed on your Windows machine.
Pull Windows Server Core Image: Pull the Windows Server Core image from Docker Hub. This image provides a minimal Windows environment that you can use as a base for running PowerShell scripts.
Open a PowerShell prompt on your host machine and run:
powershelldocker pull mcr.microsoft.com/windows/servercore:latest
Create a Dockerfile: Create a Dockerfile to build a custom Docker image that includes PowerShell and any additional dependencies you need to access TFS. In this case, you'll need the TFS PowerShell module. The Dockerfile might look like this:
Dockerfile# Use the Windows Server Core image as the base image
FROM mcr.microsoft.com/windows/servercore:latest
# Set working directory
WORKDIR /app
# Install PowerShell
RUN Add-WindowsFeature -Name PowerShell
# Install the TFS PowerShell module
RUN Install-Module -Name AzureRM.TeamFoundationServer -Force
# Set up entry point to run PowerShell
CMD ["powershell.exe"]
Build the Docker Image: In the same directory as the Dockerfile, run the following command to build the custom Docker image:
powershelldocker build -t my-powershell-image .
Replace
my-powershell-image
with a name for your custom Docker image.Run the Docker Container: Now, you can run a container based on the custom image and execute your PowerShell script:
powershelldocker run -it --rm my-powershell-image powershell.exe -File C:\path\to\your\script.ps1
Replace
C:\path\to\your\script.ps1
with the path to your PowerShell script inside the container.
Ensure that the TFS server is accessible from the Docker container. If your TFS server is on the same local network as the host machine running Docker, it should be accessible by default. If the TFS server is on a different network or requires VPN access, you may need to configure the Docker network settings accordingly.
Remember to handle any authentication or credentials required to access the TFS server from your PowerShell script.
Note: The TFS PowerShell module may vary depending on your TFS server version. Ensure that you install the correct module version that is compatible with your TFS server.