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.
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.
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.
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: 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. 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.
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.
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:
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.)
And voila! The Dev Container is just as it was before.
If you know other ways to achieve this, leave a comment or reach out, I'm always happy to learn more.
Top comments (0)