> For the complete documentation index, see [llms.txt](https://docs.percona.com/percona-monitoring-and-management/3/llms.txt).

# Run PMM Client as a Docker container

The [PMM Client Docker image](https://hub.docker.com/r/percona/pmm-client/tags/) provides a convenient way to run PMM Client as a pre-configured container without installing software directly on your host system.

Using the Docker container approach offers several advantages:

- consistent environment across different operating systems
- simplified setup and configuration process
- automatic architecture detection (x86_64/ARM64)
- [centralized configuration management](https://docs.percona.com/percona-monitoring-and-management/3/install-pmm/install-pmm-server/deployment-options/docker/env_var.md#configure-vmagent-variables) through PMM Server environment variables

## Prerequisites

Complete these essential steps before installation:

1. Install [Docker Engine](https://docs.docker.com/get-docker/).
1. Check [system requirements](https://docs.percona.com/percona-monitoring-and-management/3/install-pmm/install-pmm-client/prerequisites.md) to ensure your environment meets the minimum criteria.
1. [Install and configure PMM Server](https://docs.percona.com/percona-monitoring-and-management/3/install-pmm/install-pmm-server/index.md) as you’ll need its IP address or hostname to configure the Client.
1. [Set up firewall rules](https://docs.percona.com/percona-monitoring-and-management/3/install-pmm/plan-pmm-installation/network_and_firewall.md) to allow communication between PMM Client and PMM Server.
1. [Create database monitoring users](https://docs.percona.com/percona-monitoring-and-management/3/install-pmm/install-pmm-client/prerequisites.md#database-monitoring-requirements) with appropriate permissions for the databases you plan to monitor.
1. Use **PMM Client 3.10.0 or later**. Earlier versions register the Node again on every container start, and PMM Server responds by removing the Node together with every service on it, so services are lost on restart regardless of the volume you give it.

## Installation and setup

### Deploy and register PMM Client

Deploy PMM Client with a fixed node name and a mounted volume for its configuration file so PMM Server can identify it across restarts, container re-creations, and image upgrades. Without these, a re-created container loses its identity and its monitored services.

PMM supports two authentication methods for registration: service account tokens (recommended) and username/password credentials.

To deploy and register PMM Client using Docker:

1. Pull the PMM Client Docker image:

   ```sh
   docker pull percona/pmm-client:3
   ```

1. Start the PMM Client container and register it with PMM Server using the [pmm-agent](https://docs.percona.com/percona-monitoring-and-management/3/use/commands/pmm-agent.md) Setup mode. Replace `X.X.X.X` with the external IP address of your PMM Server:

   Important

   Do not use the `--detach` option with this command. The pmm-agent outputs logs directly to the console, and detaching would prevent you from seeing important setup information and potential errors.

   **Using Service accounts (Recommended)**

   [Service accounts](https://docs.percona.com/percona-monitoring-and-management/3/api/authentication.md) provide secure, token-based authentication for registering nodes with PMM Server. Unlike standard user credentials, service account tokens can be easily rotated, revoked, or scoped to specific permissions without affecting user access to PMM.

   To register with service accounts, create a service account then generate an authentication token that you can use to register the PMM Client:

   1. Log into PMM web interface.

   1. Navigate to **Users and access > Service accounts**.

   1. Click **Add service account**.

   1. Enter a descriptive name (e.g.: `pmm-client-prod-db01`). Keep in mind that PMM automatically shortens names exceeding 200 characters using a `{prefix}_{hash}` pattern.

   1. Select the **Admin** role from the drop-down. For detailed information about what each role can do, see [Role types in PMM](https://docs.percona.com/percona-monitoring-and-management/3/admin/roles/index.md).

   1. Click **Create > Add service account token**.

   1. (Optional) Name your token or leave blank for auto-generated name.

   1. (Optional) Set expiration date for enhanced security. Expired tokens require manual rotation. Permanent tokens remain valid until revoked.

   1. Click **Generate Token**.

   1. **Save your token immediately**. It starts with `glsa_` and won’t be shown again!

   1. Run the container using the token:

      ```bash
      docker run \
      --name pmm-client \
      -e PMM_AGENT_SETUP_NODE_NAME=my_node_name \
      -e PMM_AGENT_SETUP_NODE_TYPE=container \
      -e PMM_AGENT_SERVER_ADDRESS=X.X.X.X:443 \
      -e PMM_AGENT_SERVER_USERNAME=service_token \
      -e PMM_AGENT_SERVER_PASSWORD=YOUR_GLSA_TOKEN \
      -e PMM_AGENT_SERVER_INSECURE_TLS=1 \
      -e PMM_AGENT_SETUP=1 \
      -e PMM_AGENT_CONFIG_FILE=config/pmm-agent.yaml \
      -v pmm-client-config:/usr/local/percona/pmm/config \
      percona/pmm-client:3
      ```

      **Parameters explained:**

      - `PMM_AGENT_SETUP_NODE_NAME`: name of the Node in PMM. Keep it fixed: it defaults to the hostname, which a re-created container does not keep, and `pmm-agent setup` stops if PMM Server has the pmm-agent registered under another name
      - `pmm-client-config`: named volume holding `pmm-agent.yaml` with the identity PMM Server issued to the pmm-agent. Without it a re-created container has nothing to keep, and registering the same Node name again fails
      - `PMM_AGENT_SETUP_NODE_TYPE` - (Optional) Node type: generic, container, etc.
      - `PMM_AGENT_SERVER_ADDRESS` - Your PMM Server’s IP address or hostname
      - `service_token` - Use this exact string as the username (not a placeholder!)
      - `YOUR_GLSA_TOKEN` - The token you copied (starts with `glsa_`)
      - `PMM_AGENT_SERVER_INSECURE_TLS` - Skip certificate validation (remove for production with valid certificates)

      You can find a complete list of compatible environment variables [here](https://docs.percona.com/percona-monitoring-and-management/3/use/commands/pmm-agent.md).

   **Standard authentication (Not recommended)**

   This method exposes credentials in command history, process lists, and logs! Use only for testing or migration scenarios:

   ```sh
   docker run \
   --name pmm-client \
   -e PMM_AGENT_SETUP_NODE_NAME=my_node_name \
   -e PMM_AGENT_SETUP_NODE_TYPE=container \
   -e PMM_AGENT_SERVER_ADDRESS=X.X.X.X:443 \
   -e PMM_AGENT_SERVER_USERNAME=admin \
   -e PMM_AGENT_SERVER_PASSWORD=admin \
   -e PMM_AGENT_SERVER_INSECURE_TLS=1 \
   -e PMM_AGENT_SETUP=1 \
   -e PMM_AGENT_CONFIG_FILE=config/pmm-agent.yaml \
   -v pmm-client-config:/usr/local/percona/pmm/config \
   percona/pmm-client:3
   ```

   **Parameters explained:**

   - `PMM_AGENT_SETUP_NODE_NAME` - Name of the Node in PMM. Keep it fixed: it defaults to the hostname, which a re-created container does not keep, and `pmm-agent setup` stops when PMM Server has the pmm-agent registered under another name
   - `pmm-client-config` - Named volume holding `pmm-agent.yaml` with the identity PMM Server issued to the pmm-agent. Without it a re-created container has nothing to keep, and registering the same Node name again fails
   - `PMM_AGENT_SETUP_NODE_TYPE` - (Optional) Node type: generic, container, etc.
   - `PMM_AGENT_SERVER_ADDRESS` - Your PMM Server’s IP address or hostname
   - `admin`/`admin` - Default PMM Server username and password (change this immediately after first login)

   You can find a complete list of compatible environment variables [here](https://docs.percona.com/percona-monitoring-and-management/3/use/commands/pmm-agent.md).

   To migrate to [service accounts](https://docs.percona.com/percona-monitoring-and-management/3/api/authentication.md):

   1. Create service accounts while still using standard authentication.
   1. Test service account tokens on non-critical nodes.
   1. Gradually migrate all nodes to token authentication.
   1. Change the admin password from default.
   1. Consider restricting or disabling direct admin account usage for node registration.

Important

If you get `Failed to register pmm-agent on PMM Server: connection refused`, this typically means that the IP address is incorrect or the PMM Server is unreachable.

Recovering a Node after losing the volume

If the volume is deleted while the Node still exists in PMM, the Client cannot register that Node name again and the container exits. Add `-e PMM_AGENT_SETUP_FORCE=1` for one start to take the name over. PMM Server then removes the old Node together with every Service on it, so drop the variable again afterwards.

## Verify the connection

Run the following command to check that PMM Client is properly connected and registered:

```bash
docker exec -t pmm-client pmm-admin status
```

If the connection is successful, you should also see an increased number of monitored nodes in the PMM user interface.

### View your monitored node

To confirm your node is being monitored:

1. Go to the main menu and select **Operating System > Overview**.
1. In the **Node Names** drop-down menu, select the node you recently registered.
1. Modify the time range to view the relevant data for your selected node.

## Add monitoring services

After you install PMM Client, add the databases you want to monitor with [`pmm-admin add`](https://docs.percona.com/percona-monitoring-and-management/3/use/commands/pmm-admin/pmm-admin.md). You can add them once from inside the running container, or have the container add them every time it starts. Choose the option that fits how you manage the container:

**Add services once**

Run `pmm-admin add` in the container. PMM keeps the services you add when the container restarts, so you only need to do this once:

```bash
docker exec -t pmm-client pmm-admin add mysql --username=pmm --password=pass --query-source=perfschema --host=mysql-host
```

**Add services on every start**

To keep the services together with the container definition, for example when you recreate the container from a script, add them from a script that the container runs on every start:

1. Create a script with your `pmm-admin add` commands. Because the script runs on every start, add `|| true` to each command so that a service added on an earlier start doesn’t stop the container:

   ```bash
   #!/bin/sh
   pmm-admin add mysql --username=pmm --password=pass --query-source=perfschema --host=mysql-host || true
   ```

1. Make the script executable:

   ```bash
   chmod +x pmm-prerun.sh
   ```

1. Start the container with the script mounted and its path in `PMM_AGENT_PRERUN_FILE`:

   ```bash
   docker run \
   --name pmm-client \
   -e PMM_AGENT_SETUP_NODE_NAME=my_node_name \
   -e PMM_AGENT_SETUP_NODE_TYPE=container \
   -e PMM_AGENT_SERVER_ADDRESS=X.X.X.X:443 \
   -e PMM_AGENT_SERVER_USERNAME=service_token \
   -e PMM_AGENT_SERVER_PASSWORD=YOUR_GLSA_TOKEN \
   -e PMM_AGENT_SERVER_INSECURE_TLS=1 \
   -e PMM_AGENT_SETUP=1 \
   -e PMM_AGENT_CONFIG_FILE=config/pmm-agent.yaml \
   -v pmm-client-config:/usr/local/percona/pmm/config \
   -e PMM_AGENT_PRERUN_FILE=/opt/percona/pmm-prerun.sh \
   -v ./pmm-prerun.sh:/opt/percona/pmm-prerun.sh \
   percona/pmm-client:3
   ```

If the script fails, the container stops, unless `PMM_AGENT_SIDECAR` is set. To find out why, check the container logs with `docker logs pmm-client`.

To pass the commands directly instead of a script file, set them in `PMM_AGENT_PRERUN_SCRIPT`. For all the variables the container accepts, see [Configure the PMM Client container](https://docs.percona.com/percona-monitoring-and-management/3/use/commands/pmm-agent.md#configure-the-pmm-client-container).

## Tips for Docker configuration

- Ensure your host’s firewall and routing rules are configured to allow Docker communications. This is crucial for Docker containers to communicate properly. For more details, see the [troubleshooting checklist](https://docs.percona.com/percona-monitoring-and-management/3/troubleshoot/checklist.md).
- To view available pmm-agent command-line options, run: `docker run --rm percona/pmm-client:3 --help`
