# How do I change the way I connect to an environment without losing my existing stacks?

{% hint style="info" %}
Note that these steps apply to Docker environments only.
{% endhint %}

In the case of changing the way you connect to an environment (for example by moving from connecting to the Docker socket directly to using a socket proxy) you can move your stacks by:

{% stepper %}
{% step %}

### Removing the current environment connection in Portainer

Under **Administration**, navigate to **Environment-related**, then to **Environments**. Select the environment you would like to remove and click **Remove.** The stacks in this environment will become orphaned, and therefore available to be re-associated once you re-add the environment in the next step.

<figure><img src="https://3850702872-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXI7douejaBgpZ6CP2zJf%2Fuploads%2Fgit-blob-7f43e69f02a66b12e43a9d595cfd0c92437dc1de%2FRemove%20env.png?alt=media" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Adding a new environment using the new connection method

[Add the environment again](https://docs.portainer.io/2.33-lts/admin/environments/add) using the new connection method.
{% endstep %}

{% step %}

### Re-associating the orphaned stacks with the new environment

Within the environment that you want to associate your orphaned stacks with, click **Stacks** in the left hand menu. At the Stacks list, click on the three dots in the top right corner and select **Show all orphaned stacks**. Your stack list will then update to include any orphaned stacks.

<div align="left"><figure><img src="https://3850702872-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXI7douejaBgpZ6CP2zJf%2Fuploads%2Fgit-blob-afdcf3b0097329e535a45031c2b25226ab0e1681%2Forphaned%20stacks%20selection.png?alt=media" alt=""><figcaption></figcaption></figure></div>

Click into the stack that you want to recover, and select **Associate.**

<div align="center"><figure><img src="https://3850702872-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXI7douejaBgpZ6CP2zJf%2Fuploads%2Fgit-blob-ef088010f45abedaf4f42ec8be8353fbee463447%2Fassociate.png?alt=media" alt=""><figcaption></figcaption></figure></div>

Your stack will now appear in your stack list with total control. Repeat this process for each stack you want to re-associate.&#x20;
{% endstep %}
{% endstepper %}
