[Yandex Cloud documentation](../../../index.md) > [Yandex API Gateway](../../index.md) > [Concepts](../index.md) > [Trigger](index.md) > Trigger for Container Registry

# Trigger for Container Registry that sends messages to WebSocket connections

A [trigger](index.md) for Container Registry sends messages to [WebSocket connections](../extensions/websocket.md) when certain events occur with a Container Registry [Docker image](../../../container-registry/concepts/docker-image.md). The trigger must be in the same cloud as the [registry](../../../container-registry/concepts/registry.md) whose events it is subscribed to.

A trigger for Container Registry requires a [service account](../../../iam/concepts/users/service-accounts.md) to send messages to WebSocket connections.

For more information about creating a trigger for Container Registry, see [Creating a trigger for Container Registry that sends messages to WebSocket connections](../../operations/trigger/cr-trigger-create.md).

## Events for setting up a trigger {#event}

Events with Docker images that can be tracked using a trigger:
* [Creating a Docker image](../../../container-registry/operations/docker-image/docker-image-push.md).
* [Deleting a Docker image](../../../container-registry/operations/docker-image/docker-image-delete.md).
* Creating a Docker image tag.
* Deleting a Docker image tag.

A Docker image is always pushed with a tag (if no tag is specified, Docker automatically assigns the `latest` tag), meaning the `CreateImage` event always comes with `CreateImageTag`. You can add any number of tags to a Docker image by pushing the same image with different tags. In this case, only the `CreateImageTag` event occurs, without `CreateImage`.

A tag can be reassigned from one Docker image to another. This happens when pushing a new Docker image with a tag that is already used in another Docker image. In this case, the `CreateImage` event will occur for the new Docker image. In this case, changing the tag will trigger two events: `DeleteImageTag` (removing the tag from the old Docker image) and `CreateImageTag` (assigning the tag to the new Docker image).

Deleting a Docker image also deletes all its tags. This is why deleting a Docker image always triggers the `DeleteImage` event and as many `DeleteImageTag` events as the Docker image had tags at the time of deletion.

### Filtering events {#filter}

Events are filtered using tags and names of Docker images you push. When using a name and a tag at the same time, filtering is based on the logical `AND`: for the trigger to fire, the image must match both the name and the tag.

## Event batching {#batching}

The grouping settings allow sending several events to WebSocket connections in one go. They set a top limit on event group size and on event group accumulation time. For example, if the event group size is 3, WebSocket connections can receive groups containing from 1 to 3 events.

## Roles required for the proper operation of a trigger for Container Registry {#roles}

* To create a trigger, you need:
    * Permission for the service account under which the trigger runs the operation. This permission comes with the [iam.serviceAccounts.user](../../../iam/security/index.md#iam-serviceAccounts-user) and [editor](../../../iam/roles-reference.md#editor) roles or higher.
    * The `container-registry.images.puller` role for the registry whose events are processed by the trigger.
* For the trigger to fire, the service account needs the `api-gateway.websocketBroadcaster` role for the folder containing the API gateway.

Read more about [access management](../../security/index.md).

## Container Registry trigger message format {#format}

After the trigger fires, it will send the following message to WebSocket connections:

```json
{
  "messages": [
  {
    "event_metadata": {
      "cloud_id": "b1gvlrnlw2e6********",
      "created_at": "2020-09-07T11:09:14Z",
      "event_id": "crtpk611vb7g********",
      "event_type": "yandex.cloud.events.containerregistry.CreateImage",
      "folder_id": "b1g88tfl0pl8********",
      "tracing_context": {
        "parent_span_id": "-14915794679********",
        "span_id": "-72326631357********",
        "trace_id": "70e7m4n2********"
      }
    },
    "details": {
      "image_digest": "sha256:45f8f740272f1f2a053eade37d8d************************************",
      "image_id": "crti2c9b************",
      "registry_id": "crt2504s************",
      "repository_name": "crt2504s************/ubuntu",
      "tag": "latest"
    }
  }]
}
```

## Useful links {#see-also}

* [Trigger for Container Registry that runs a Serverless Containers container](../../../serverless-containers/concepts/trigger/cr-trigger.md)
* [Trigger for Container Registry that runs a Cloud Functions function](../../../functions/concepts/trigger/cr-trigger.md)