Back to Blog
tutorialIntermediate5 min read

Docker Desktop Portainer Agent

Connect to a Portainer Host via an Agent in Windows using Docker Desktop.

If you are looking to set up a Portainer Host, see the Docker Desktop Portainer Host guide.

Prerequisites

  1. Docker Desktop installed

Portainer Agent

Open up Portainer and go to the "Environments" section. Then click the "Add Environment" button (top right).

Select "Docker Standalone" and then the "Start Wizard" button.

Make sure "Agent" is selected. There is a command listed there, unfortunately you cannot copy and paste this into the PowerShell terminal. PowerShell does not like the backslashes. Instead they must be replaced with backticks. You can copy the code below:

docker run -d `
  -p 9001:9001 `
  --name portainer_agent `
  --restart=always `
  -v /var/run/docker.sock:/var/run/docker.sock `
  -v /var/lib/docker/volumes:/var/lib/docker/volumes `
  -v /:/host `
  portainer/agent:<INSERT VERSION>

But make sure to grab the version from the command shown in Portainer.

Open up a terminal in Windows with win + x and then select "Terminal". Paste in the command. It should download the image and deploy the container.

PowerShell terminal deploying portainer agent
Portainer Agent - Docker Pull in PowerShell

After it is finished, it should be visible in Docker Desktop.

Portainer agent container running in Docker Desktop
Portainer Agent Running in Docker Desktop

Now go back to Portainer, at the bottom enter a name for your new environment, along with the IP address and port. To get the IP address use ipconfig

ipconfig

Then find the "IPv4 Address" for the appropriate LAN Adapter. On my setup it is the WiFi Adapter:

ipconfig output showing WiFi adapter IPv4 address
ipconfig - WiFi Adapter IPv4 Address

I will name this environment "optimus" and use the IP from ipconfig.

Portainer environment name and address configuration
Portainer Environment Name and Address Configuration

Then click the "Connect" button, you should see a success message. After returning to the Home page, the new environment should now be visible.

Portainer home showing optimus environment connected
Portainer Home - Optimus Environment Connected