How to re-open a repository cloned in a volume, from Visual Studio Code
Tags: devcaontainer, docker, git, vscode
Published: 2022-05-10 12:42:22

---
title: How to re-open a repository cloned in a volume, from Visual Studio Code
published: true
date: 2022-05-10 08:07:00 UTC
tags: devcaontainer,docker,git,vscode
canonical_url: https://www.frankysnotes.com/2022/05/how-to-re-open-repository-cloned-in.html
---

I love Dev Containers, I use them a lot for most of my development. One of my favorite options is to clone a repository directly in a docker volume.

[![](https://blogger.googleusercontent.com/img/a/AVvXsEgv-wb2cWmSJzv-CYAmsaENepJE6dGYt9EGowNHnqxWjGo9IOX1trjK6vdNnflRDS1V_wK-MH1Z_ZN9Hyirci2Do8fEs6TjAeiK_tq-U4a5ACdM-O3OYe5wok2poFBZqBCROtX7sq3iayEiASAQWTidY4dvl9mz_WFaDgLn4gJT8DusacdFNIPpTxFH=w556-h327)](https://blogger.googleusercontent.com/img/a/AVvXsEgv-wb2cWmSJzv-CYAmsaENepJE6dGYt9EGowNHnqxWjGo9IOX1trjK6vdNnflRDS1V_wK-MH1Z_ZN9Hyirci2Do8fEs6TjAeiK_tq-U4a5ACdM-O3OYe5wok2poFBZqBCROtX7sq3iayEiASAQWTidY4dvl9mz_WFaDgLn4gJT8DusacdFNIPpTxFH)
  

It takes a few seconds and you can work on your code without installing any SDKs or language that your current machine doesn't have. Marvelous!

Ideally, at the end of your session, you push your code to another repository (ex: GitHub). However, sometimes I forget or am interrupted I start working on something else, and my changes are not pushed.

How do you re-open that environment?! In this post, I want to share two ways that I use.

## Open Recent

The first method is to use the history of the editor! For example, here in Visual Studio Code, select the _File_ menu and _Open Recent_.

[![](https://blogger.googleusercontent.com/img/a/AVvXsEhsWE7h47oTVxgZlqCb5lzOrFK6nTe5HICzQNRlswEAha_EGCOp5SjxEVVExTDamspXNRKRHsYIOlK9e70z7O89ToyPolEozAK-5uBmGA4eb8l_ZX5DyU5GWMLbGPsJrm8R4zIJbE9GFNtnHT9r1pvsabh4ANgNACXcnG0bcugfXX5JfwIyG-5uTrja=w577-h218)](https://blogger.googleusercontent.com/img/a/AVvXsEhsWE7h47oTVxgZlqCb5lzOrFK6nTe5HICzQNRlswEAha_EGCOp5SjxEVVExTDamspXNRKRHsYIOlK9e70z7O89ToyPolEozAK-5uBmGA4eb8l_ZX5DyU5GWMLbGPsJrm8R4zIJbE9GFNtnHT9r1pvsabh4ANgNACXcnG0bcugfXX5JfwIyG-5uTrja)
  

If you didn't open too many files since you used that dev container, it should be present as displayed in the image. It should look like: <Name of the repository> in a unique [Dev Container].

Make sure docker is already running and select it. Voila, in a snap you are back into the dev environment with your last changes waiting for you.

## Open the Container

There are a few different options to do the next solution, I will share the one I consider the easiest for the people who are not Docker experts.

First, if not already present to your VSCode, add the Docker extension identifier: [ms-azuretools.vscode-docker](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker). Then from this new extension in the top section named _containers_ search for your container. It should start with "vsc", for Visual Studio Code, then hyphen the name of the repository you cloned. Right-click on it and select **start**. After a few seconds, the container should have a little green triangle on its side and be ready to continue.

[![](https://blogger.googleusercontent.com/img/a/AVvXsEjknPnw2cqXhKnBno4BOBDAcCjHBw0iBDtKtRVz35owQC89fGi6mMvct3tSu_wQRuOkPXUM8zoBDUgF30KafL3uf0fQ3xW0mlrzexo-s7pJ8LFygV-zes7WaPCQCcd_wVcHV7sAxBKbml97fUvi9QrC3iAzP0_ZuZjjSMmM5_6qxEBDGnF_8JwfVe7W=w550-h366)](https://blogger.googleusercontent.com/img/a/AVvXsEjknPnw2cqXhKnBno4BOBDAcCjHBw0iBDtKtRVz35owQC89fGi6mMvct3tSu_wQRuOkPXUM8zoBDUgF30KafL3uf0fQ3xW0mlrzexo-s7pJ8LFygV-zes7WaPCQCcd_wVcHV7sAxBKbml97fUvi9QrC3iAzP0_ZuZjjSMmM5_6qxEBDGnF_8JwfVe7W)
  

The next step consists of attaching the container to VSCode. Once more, from the Docker extension, right-click on the container and select **Attach Visual Studio Code**.

[![](https://blogger.googleusercontent.com/img/a/AVvXsEjJWtMFGghKmyb5cHrPN4Xv1jrCCcsmXozP14XQHqOBHtzXTJ8RGhGggnYK39wQKMD94GUhNM6ZVBRA-VQTca_3flEqr1j7dtSjI5vamI3lFtHLlPvdGOLp9kKDtEyU974hf0px8TT6vqjQDI1FTDS2PBcWGOCWuR4XshatkwYX5K-m4VCCvlC3Kq95=w559-h400)](https://blogger.googleusercontent.com/img/a/AVvXsEjJWtMFGghKmyb5cHrPN4Xv1jrCCcsmXozP14XQHqOBHtzXTJ8RGhGggnYK39wQKMD94GUhNM6ZVBRA-VQTca_3flEqr1j7dtSjI5vamI3lFtHLlPvdGOLp9kKDtEyU974hf0px8TT6vqjQDI1FTDS2PBcWGOCWuR4XshatkwYX5K-m4VCCvlC3Kq95)
  

This will open a new VSCode window, we are mostly done but there is one last step to do. You will notice that the file explorer is empty. No worries we will fix everything with this last step. The terminal should be open in the home folder of the _root_ user. Let's open our project folder by executing the command:

```
cd /workspaces/<repository-name>
```

Then the final command is to re-open VSCode in this folder and let the Dev Container do his magic. Execute the command:

```
code . -r
```

(the _-r_ is to re-use the same VSCode windows. It's optional, if not provided it will open a new VSCode instance.)

[![](https://blogger.googleusercontent.com/img/a/AVvXsEj4-qRWL5JFShsb4t_h3gh2m-gBbivE4JE2eJTKFXgrXYeYnR60oKAw2gJgRvlBvu9jhydPHTTffz1D6AlK80MXkXcSsUVg05iF14C_r_BAJ0PLqY2HpMKPuPx8NISQKPiOdr_mxQ8izu_ML5PzNcduXP-NZ1YDLKLpR1y28hI5Yi-x5o0mwiqnECiN=w557-h242)](https://blogger.googleusercontent.com/img/a/AVvXsEj4-qRWL5JFShsb4t_h3gh2m-gBbivE4JE2eJTKFXgrXYeYnR60oKAw2gJgRvlBvu9jhydPHTTffz1D6AlK80MXkXcSsUVg05iF14C_r_BAJ0PLqY2HpMKPuPx8NISQKPiOdr_mxQ8izu_ML5PzNcduXP-NZ1YDLKLpR1y28hI5Yi-x5o0mwiqnECiN)
  

And voila! The Dev Container is just as it was before.

[![](https://blogger.googleusercontent.com/img/a/AVvXsEhLE07PHgEbvNtrSA-CoG8Xqbj-eD7a1T6NQelONV6f1mvDSoRNImWpW0km0XeeZFqZQ8Ux5KgrWVfHkq0ZdfPjh4oTKv0v6Qu-m24MN8_AMc51Rc7qk2utnl-_blQU4-3KOLR_FbFhtPWtLHweatr-zg6ENC6SFvpd-6DnVa0HIhRn8DZ4weBHG9eq=w572-h310)](https://blogger.googleusercontent.com/img/a/AVvXsEhLE07PHgEbvNtrSA-CoG8Xqbj-eD7a1T6NQelONV6f1mvDSoRNImWpW0km0XeeZFqZQ8Ux5KgrWVfHkq0ZdfPjh4oTKv0v6Qu-m24MN8_AMc51Rc7qk2utnl-_blQU4-3KOLR_FbFhtPWtLHweatr-zg6ENC6SFvpd-6DnVa0HIhRn8DZ4weBHG9eq)
  

If you know other ways to achieve this, leave a comment or reach out, I'm always happy to learn more.

~ frank