Set up Azure Shell locally - part 2
Published Nov 16 2020 12:00 AM 3,699 Views
Microsoft

Hello Folks,

 

In my last post I discussed how you can run the managed image that the Azure Cloud Shell is based on locally.  It allows you to leverage the Azure Shell managed environment without being subject to the limitations of the real Azure Cloud Shell.

 

Following that post, someone said to me, “You forgot that online you can use code (Cloud Shell editor)”.

 

Well.  Yes and no…

 

Let me elaborate… No, you cannot use the same Code version in the shell.

Picture1.png

 

However, there is a great way to use the container version WITH the full Visual Studio Code.   I must admit that I MUCH prefer it this way. Mostly because I can use all the extensions in VS Code that make my life easier.  Extensions like:

To name a few.

Here’s how I set that up, so I get the best of both worlds.  A managed Cloud Shell environment and a local powerful code editor.

 

Connecting to VS Code to the Running container

So,  we already covered how we setup and start the container in the last post. Now to connect VS Code to the container we need to get one more extension.  The Remote - Containers extension lets you use a Docker container as a full-featured environment.  To quickly swap between different, isolated development environments and safely make updates without worrying about impacting your local machine.

 

Picture2.png

 

Once it’s installed, I press F1 to bring up the Command Palette and type in Remote-Containers for a full list of commands.

 

Picture3.png

 

You can also click on the Remote "Quick Access" status bar item to get a list of the most common commands.

 

 

Picture4.png

 

From the Command Palette select “Remote-Containers: Attach to Running Container…”

 

 

 

Picture5.png

 

A list of running containers will be presented and I select the one that’s running my “Local Cloud Shell”.

 

Picture6.png

 

It will ten connect to the container environment.

 

Picture7.png

 

Connecting to the mapped folder inside the container

Connecting to the mapped folder is as easy as opening a folder and navigating to the folder in the container mapped to the local location.

 

vscode-folder.gif

 

The last piece of this puzzle is the terminal. Because I’m connected to the container, I have access to all the environments that are setup in there. By selecting ‘Terminal’ from the ‘view’ menu I can open the default environment which is a bash shell.


But I can easily open a PowerShell terminal by selecting “Select Default Shell” in the terminal shell selection drop down.

 

Picture8.png

 

And selecting the PowerShell Core environment setup in the image of the cloud shell.

 

Picture9.png

 

And finally, starting a new terminal either by selecting ‘New Terminal” in the Terminal menu, or clicking the ‘+” in the terminal view.

 

Picture10.png

 

From there you are using the Cloud Shell Image and all the tools that are configured in it, it’s always up to date and you get access to the full power of VS Code instead of the Code “light” editor available in the Online Azure Cloud Shell.


So, to address the comment, “You forgot that online you can use code (Cloud Shell editor)”. I say. You’re right, but I got something better!


I hope this helps!


Cheers!


Pierre

 

Version history
Last update:
‎Nov 16 2020 06:46 PM
Updated by: