--- title: "Create a replication rule" description: "Copy images from a source registry into a Container Registry project with a replication rule, run when you choose or on a schedule." content_type: "how-to" product: "container-registry" platform: "MyAccount" url: "/myaccount/container-registry/how-to/create-a-replication-rule/" topic: ["copy-images-from-other-registries"] relationships: {"requires":["/myaccount/container-registry/how-to/add-a-source-registry/"]} --- # Create a replication rule A replication rule copies images from one source registry into your registry project, when you run it or on a schedule. The images always land in the project that holds the rule. ## Before you begin Add the source registry to this project first. If you are a team member, your role also needs the create permission for Container Registry. See [Add a source registry](/myaccount/container-registry/how-to/add-a-source-registry/). ## Open the rule form In MyAccount, under **Storage**, click **Container Registry**, and click your project. Open its **Replications Rules** tab, headed **Manage Replication Rules**. Click **+** (**New Replication Rules**). **Create Replication Rule** opens. ## Name the rule and choose the source 1. In **Name**, enter a name for the rule. It starts with a lowercase letter, uses the same characters as a project name, and must be unused in this project. 2. (Optional) In **Description**, add a note about what the rule copies. 3. In **Source registry**, choose the source registry to copy from. ## Choose how much of the path to keep **Flattening Level** sets how much of each image's path at the source is kept in your project. For an image at `a/b/c/d/img` in the source registry: | **Flattening Level** | Path in your project | | ---------------------- | ---------------------------- | | **Flatten All Levels** | `/img` | | **No Flatting** | `/a/b/c/d/img` | | **Flatten 1 Level** | `/b/c/d/img` | | **Flatten 2 Levels** | `/c/d/img` | | **Flatten 3 Levels** | `/d/img` | A new rule starts at **Flatten All Levels**, which puts every image straight under your project. Choose **No Flatting** to keep the full source path, for example when two images at the source share a name in different folders. ## Choose when the rule runs In **Trigger Mode**, choose one: - **Manual**: the rule runs each time you click **Execute**. A new rule starts at **Manual**. - **Scheduled**: the rule runs on the schedule in **Cron String**, a five-field cron expression in UTC. The form spells the schedule out in words as you type. The string starts with the minute as a number; for example, `5 2 * * *` runs the rule at 02:05 UTC every day. ## (Optional) Filter what is copied Under **Filters**, limit the rule to some images. **Name:** matches image names. **Tag:** matches tags, and only **Tag:** has a choice of **matching**, to copy the tags that match, or **excluding**, to copy every other tag. - An empty value or `**` matches everything. - `library/**` matches only what is under `library`. - `1.0*` matches tags that start with `1.0`. ## Create the rule Click **Create**. You see **Replication Policy Created Successfully**, and the rule is listed on the **Replications Rules** tab with its **Name**, **Source Registry**, **State**, **Trigger Type**, **Description**, and **Updated Time**. A new rule reads **Enabled**. ## Run the rule In MyAccount, under **Storage**, click **Container Registry**, click your project, and open its **Replications Rules** tab. Open the rule's **Actions** menu and click **Execute**. A run starts, with **Policy Execution Created Successfully**. **Execute** runs a rule that reads **Enabled**; to run a disabled rule, turn it on first, as in [Edit or turn off a rule](#edit-or-turn-off-a-rule). To follow the run, click the rule. **Executions : ** opens, with each run's **ID**, **Status**, **Trigger**, and **Start Time**. A **Failed** run gives the reason it failed. To stop a run that reads **InProgress**, open its menu and click **Stop**. The copied images appear in your project's repositories. If the rule or its run is refused, see [Troubleshooting Container Registry](/myaccount/container-registry/troubleshooting/container-registry/). ## Edit or turn off a rule 1. In MyAccount, under **Storage**, click **Container Registry**, click your project, and open its **Replications Rules** tab. Open the rule's **Actions** menu and click **Edit**. The rule form opens with **Enable Rule** added. 2. Change the settings you need. To pause the rule, clear **Enable Rule**; to turn it back on, check it. Its **State** then reads **Disabled** or **Enabled**. 3. Click **Update**. ## Delete a rule In MyAccount, under **Storage**, click **Container Registry**, click your project, and open its **Replications Rules** tab. Open the rule's **Actions** menu and click **Delete**. Confirm the prompt, which names the rule, to delete it. Your project now copies images from the source registry by the rule you set. To remove images it no longer needs, see [Clean up unused images](/myaccount/container-registry/how-to/clean-up-unused-images/).