October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk10 min

How to Deploy Portainer Agent With Docker Compose

A complete guide to running Portainer Agent with Docker Compose, including the exact mounts and port mapping, optional AGENT_SECRET authentication, host-management access, Swarm global mode and a practical troubleshooting sequence.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a standalone Docker host, deploy the portainer/agent image with Docker Compose, mount the Docker socket and Docker volume directory, and publish TCP port 9001. Then add the host in Portainer Server as an Agent environment using the host’s DNS name or IP address and the same port. If you configure AGENT_SECRET, the Server and Agent values must match exactly.

What Portainer Agent does

Portainer Agent is a containerized API proxy. It runs next to Docker and gives Portainer Server a way to manage that Docker environment. The Agent is not a replacement for Docker Engine: it needs access to Docker’s Unix socket and, for volume management, the host directory where Docker stores volumes.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The deployment model determines how Portainer Server reaches the Agent:

  • Standalone Docker host: one Compose service runs on one host, and Portainer Server connects to that host’s DNS name or IP address on TCP port 9001.
  • Docker Swarm: a global service places one Agent task on every node. Agents use an overlay network and service discovery; a host-mode port publication is needed when Portainer Server is outside the overlay.

Requirements before you deploy

  • A running Docker Engine on the host where the Agent will run.
  • Docker Compose support through the docker compose command.
  • Permission to read the Docker socket and the host Docker volume directory from the Agent container.
  • A network path from Portainer Server to the Agent host. For the default configuration, that path must permit TCP 9001.
  • A DNS name or IP address that Portainer Server can resolve and route to the Agent host.

Decide whether you need host-management features before writing the file. They are disabled by default. Enabling them requires an additional host-root bind mount and gives the Agent access for host filesystem and hardware operations, so do not add that access unless those features are required.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Standalone deployment with Docker Compose

1. Create a protected working directory

On the Docker host, create a directory for the Compose project and restrict access to it. The directory will contain the Compose file and, optionally, an environment file holding the Agent secret.

mkdir -p ~/portainer-agent
cd ~/portainer-agent

The exact directory is not important. What matters is that the account running Compose can read it and that other users cannot casually read a secret stored there.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Store the optional secret outside the Compose file

Create an .env file in the project directory if you want shared-secret authentication:

AGENT_SECRET=replace-with-a-long-random-value

Protect the file so only the intended administrator can read it:

chmod 600 .env

Do not commit this file to source control or paste its value into support requests. The value shown here is a placeholder for your own secret; the Server must be configured with the identical value when it requires Agent-secret authentication.

3. Write the Compose file

Save the following as compose.yml (or docker-compose.yml) in the same directory:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
services:
  portainer-agent:
    image: portainer/agent
    restart: unless-stopped
    environment:
      AGENT_SECRET: ${AGENT_SECRET}
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/docker/volumes:/var/lib/docker/volumes
    ports:
      - "9001:9001"

The restart: unless-stopped policy brings the Agent back after a Docker restart while still allowing an administrator to stop it intentionally. The two bind mounts are the standard standalone requirements. The port mapping publishes the Agent’s default API port on the host.

4. Understand each port and mount

Compose item Purpose When to change it
9001:9001 Publishes host TCP port 9001 to the Agent’s container port 9001 so Portainer Server can connect. Change the host-side port if another process already uses 9001. If you change the Agent’s listening port with AGENT_PORT, update the container-side mapping and the Portainer connection entry accordingly.
/var/run/docker.sock:/var/run/docker.sock Lets the Agent communicate with Docker Engine on the host. Keep the container destination unchanged. If Docker’s socket is located elsewhere, use that host path as the source.
/var/lib/docker/volumes:/var/lib/docker/volumes Exposes Docker’s volume directory so the Agent can manage Docker volumes. If Docker stores volumes in a non-standard host directory, replace only the source path and keep /var/lib/docker/volumes as the container destination.
AGENT_SECRET Optionally authenticates Portainer Server connections carrying the same secret. Set it when your Server configuration requires a secret. The value must match exactly on both sides.

Mounting the Docker socket gives the container access to Docker’s control interface. Treat the Agent host and its Compose project as administrative infrastructure, and limit network access to the Agent port to the Portainer Server or other explicitly authorized systems.

5. Validate and start the service

Render the Compose configuration first. This catches YAML errors and confirms that the environment variable is being read:

docker compose config

Then start the Agent in the background:

docker compose up -d

Check that the container is running and inspect its logs if necessary:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
docker compose ps
docker compose logs --tail=100 portainer-agent

A running container confirms that Docker started the process; it does not by itself prove that Portainer Server can reach the published port. Test the network path from the Server host or its network namespace using your normal TCP connectivity tools, and check any host firewall or cloud network policy that could block port 9001.

Connect the Agent to Portainer Server

After the Compose service is running, use Portainer Server’s environment-add flow and choose the Agent environment type. Enter the DNS name or IP address of the Docker host and port 9001, unless you deliberately changed the Agent port.

Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
  1. Confirm the address resolves from the Portainer Server host, not merely from your workstation.
  2. Confirm a route exists between the Server and the Docker host.
  3. Allow TCP 9001 through the host firewall and any intervening network policy.
  4. Enter the host address and Agent port in the environment-add form.
  5. If secret authentication is enabled, configure the Server with exactly the same AGENT_SECRET value used by the Compose project.

If Portainer reports a connection failure, keep the address in the form as the address that the Server can actually resolve and reach. A hostname that works in your browser may not resolve inside the Server’s container or on a separate machine.

Changing the Agent port

The default Agent API port is 9001. The Agent can use another port through AGENT_PORT. Change both the listening port and the published mapping so the values remain consistent:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
services:
  portainer-agent:
    image: portainer/agent
    restart: unless-stopped
    environment:
      AGENT_PORT: 9101
      AGENT_SECRET: ${AGENT_SECRET}
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/docker/volumes:/var/lib/docker/volumes
    ports:
      - "9101:9101"

After recreating the service, enter port 9101 in Portainer Server and open that port in the relevant firewall rules. A common mistake is changing only the host-side port, for example 9101:9001, and then entering 9101 as though the Agent itself were listening there. That mapping leaves the Agent listening on 9001 inside the container; use the actual container port when configuring the Server.

Enabling host-management features

Host-management features are off by default. To enable them, add the capability environment variable and bind the host root to /host:

services:
  portainer-agent:
    image: portainer/agent
    restart: unless-stopped
    environment:
      AGENT_SECRET: ${AGENT_SECRET}
      CAP_HOST_MANAGEMENT: 1
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/docker/volumes:/var/lib/docker/volumes
      - /:/host
    ports:
      - "9001:9001"

The /:/host bind mount exposes the host filesystem to the Agent for the operations those features require. Because this is substantially broader access than the standard deployment, use it only when you have a specific host-management need and protect the Agent endpoint accordingly.

Deploying the Agent on Docker Swarm

Swarm is a different deployment pattern from a single-host Compose project. Deploy the Agent as a global service so every Swarm node receives an Agent task. Connect the service to an overlay network and configure cluster discovery with AGENT_CLUSTER_ADDR.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

A representative stack definition is:

services:
  portainer_agent:
    image: portainer/agent
    environment:
      AGENT_CLUSTER_ADDR: tasks.portainer_agent:9001
      AGENT_SECRET: ${AGENT_SECRET}
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/docker/volumes:/var/lib/docker/volumes
    networks:
      - agent_overlay
    deploy:
      mode: global
    ports:
      - target: 9001
        published: 9001
        protocol: tcp
        mode: host

networks:
  agent_overlay:
    driver: overlay

AGENT_CLUSTER_ADDR is mandatory for clustered Agent discovery. The documented service-discovery form is tasks.<AGENT_SERVICE_NAME>:<AGENT_PORT>; in the example, the service name is portainer_agent and the port is 9001.

The host-mode publication in the example is appropriate when Portainer Server is outside the Swarm overlay and must reach an Agent through a node address. If Portainer Server and the Agents share the overlay, internal networking may be sufficient and a host-published port may not be necessary. Choose one connectivity model deliberately rather than publishing ports by habit.

Deploy the stack with your normal Swarm stack command, then verify that a task exists on each node and that the overlay network is attached. When connecting the environment in Portainer Server, use an address and port reachable from the Server. An internal Swarm address is appropriate only when the Server can resolve and route to that overlay service.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Standalone Compose versus Swarm

Decision point Standalone Compose Swarm
Scheduler Docker on one host runs one Agent service. Swarm schedules a global service.
Placement One container on the selected Docker host. One Agent task on each Swarm node.
Networking Publish a host port, normally 9001, for the Server. Use an overlay network; publish 9001 in host mode when the Server is outside the overlay.
Discovery Enter the host DNS name or IP plus the Agent port. Use the reachable Swarm or node address; clustered discovery uses AGENT_CLUSTER_ADDR.
Best fit A single Docker server that Portainer Server can reach directly. A multi-node Docker cluster requiring an Agent on every node.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Security and operational practices

Restrict the Agent network path

Port 9001 is the management endpoint used by Portainer Server. Permit it only from the systems that need to administer the Docker environment. If the host is reachable across untrusted networks, place it behind appropriate network controls rather than exposing the port broadly.

Protect the secret

Keep AGENT_SECRET in a protected environment file or another secret-management mechanism. A mismatch is an authentication failure, not a connectivity problem: first establish that the port is reachable, then compare the Server and Agent values character for character.

Limit host access

The standard socket and volume mounts are already privileged integration points. Adding CAP_HOST_MANAGEMENT=1 and /:/host expands access further. Leave those settings out for ordinary container and volume administration.

Preserve the volume path

When Docker uses a custom volume root, change the source side of the bind mount only. The Agent’s destination should remain /var/lib/docker/volumes so it sees the expected path inside the container.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshooting in the fastest order

Work from the local process outward. This avoids spending time on DNS or firewall changes when the container never started.

  1. Check the service or task. Run docker compose ps and inspect docker compose logs --tail=100 portainer-agent. In Swarm, verify that the global service has a running task on the expected node.
  2. Check the mounts. Confirm that /var/run/docker.sock exists on the host and that the Docker volume directory is the correct source path. A non-standard Docker data location requires changing that source bind path.
  3. Check permissions. The container must be able to use the Docker socket and read the mounted volume directory. Permission errors normally appear in the Agent logs.
  4. Check port reachability. From the Portainer Server side, test TCP 9001 (or your chosen port). Review host firewall rules, security groups and network policies.
  5. Check name resolution. Resolve the exact hostname entered in Portainer from the Server host or container. If it resolves to the wrong interface or an unreachable private address, use a reachable DNS name or IP.
  6. Check the network model. For Swarm, confirm that both sides are using the intended overlay or host-published path. A node-local published port and an overlay-only address are not interchangeable.
  7. Check secrets last. If networking works but authentication fails, compare the Server and Agent AGENT_SECRET values exactly, including capitalization and whitespace.
Symptom Likely cause Correction
Container exits immediately Invalid Compose configuration, missing environment expansion or an Agent startup error. Run docker compose config, then read the complete service log.
Agent runs but Portainer cannot connect Port 9001 is blocked, the address is not resolvable from Portainer Server, or the wrong port was entered. Test resolution and TCP reachability from the Server side and verify the published mapping.
Docker resources are unavailable The Docker socket is absent, mounted at the wrong path or inaccessible to the container. Restore the socket bind mount and correct the host-side path or permissions.
Volumes are missing The host’s Docker volume directory is non-standard or the source bind path is wrong. Bind the actual host volume directory to /var/lib/docker/volumes inside the container.
Authentication fails after networking is fixed AGENT_SECRET differs between Server and Agent. Set one identical value on both sides and recreate the service if the environment changed.
Swarm nodes are not discovered Agent is not global, the overlay network is unavailable, or AGENT_CLUSTER_ADDR is missing or malformed. Use global mode, attach the overlay, and set the documented tasks.<service>:<port> address.

Safe changes and removal

When changing mounts, ports or environment variables, edit the Compose file, validate it, and recreate the service:

docker compose config
docker compose up -d

Review the resulting container and logs after each change. If you need to stop the standalone deployment, use:

docker compose down

This removes the Compose-managed Agent container and network. The bind-mounted Docker socket and host volume directory remain on the host because they are host paths, not Compose-created data volumes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Deployment checklist

  • The image is portainer/agent.
  • The Docker socket is mounted at /var/run/docker.sock.
  • The host Docker volume directory is mounted at /var/lib/docker/volumes.
  • TCP 9001 is published and allowed through the network path, unless you intentionally chose another port.
  • The hostname or IP entered in Portainer resolves from Portainer Server.
  • Any configured AGENT_SECRET matches exactly on Server and Agent.
  • Host-management access is omitted unless it is specifically needed.
  • Swarm deployments use global mode, overlay networking and the required AGENT_CLUSTER_ADDR.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.