iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🖋

Access Multipass Ubuntu 20.04 via VS Code Remote-SSH on macOS

に公開
2022/02/15

Introduction

https://zenn.dev/s_ryuuki/articles/65f0b1c39cafbe
↑ Access the environment created above using the Visual Studio Code Remote-SSH plugin.

Environment

  • Visual Studio Code 1.64.1 [1]
    • Remote-SSH v0.70.0
    • Japanese Language Pack for Visual Studio Code

Remote-SSH

https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh
A plugin for connecting to Multipass Ubuntu from within VS Code.

Installing the Plugin

  1. Select Extensions
  2. Enter "REMOTE SSH" in the search box


3. Click "Remote - SSH"
4. Press the "Install" button

Connecting to Multipass Ubuntu 20.04

  1. Select Remote Explorer
  2. Right-click "docker-vm.local" [2] (The connection menu will be displayed)


Select "Connect to Host in Current Window".


If "SSH: docker-vm.local" is displayed in the bottom left, the connection is successful.

*If a warning appears

When recreating a virtual machine (VM), a "Warning: the ECDSA host key for ..." warning may appear.
It will stop appearing if you delete the lines indicated by the numbers after the colon in the file underlined in red (lines 6 and 7 of ~/.ssh/known_hosts).

Disconnecting from Multipass Ubuntu 20.04

  1. Click "SSH: docker-vm.local" in the bottom left
  2. Click "Close Remote Connection" from the menu

Usage

Basically, it can be used in the same way as using VS Code locally.

Connection Settings

A folder named "~/.vscode-server" is created in Multipass Ubuntu 20.04.
Configuration files are created and plugins are installed under "~/.vscode-server".

Terminal

Access Ubuntu from VS Code without starting the Mac terminal.


Click "Terminal" -> "New Terminal" from the menu.


A terminal opens within VS Code.
You can use the shell from within VS Code without having to manually log into Multipass.

Opening folders in Ubuntu 20.04

  1. Select Explorer
  2. Click "Open Folder"


Click "localstack-0.13.0" in the "Open File or Folder" dialog.


Press the "OK" button.


Press the "Yes, I trust the authors. Trust folder and enable all features" button. [3]


The file list is displayed just like in normal use.
Clicking README.md displays the contents of the file.

Docker plugin

https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker
Enables Docker operations from within VS Code.

  1. Enter "docker" in the extensions search box
  2. Press the "Install" button next to the Docker plugin.


The Docker icon is added to the sidebar.


Running Docker information is displayed. [4]
Also, you can browse information within images.


Right-clicking a running Docker container displays a menu.
You can execute various functions.

Port Forwarding

Add port forwarding settings to allow access from the Mac side to LocalStack running via docker-compose.


There is a "Ports" tab in the same area as the terminal.

  1. Select the Ports tab
  2. Press the "Forward a Port" button


Click "Port number or address"


Enter "4566" and press the Enter (return) key.


Confirm that the setting has been added.


Access LocalStack from the Mac terminal using the curl command.

% curl -s http://localhost:4566/health | jq
{
  "features": {
    "initScripts": "initialized"
  },
  "services": {
    "acm": "available",
    "apigateway": "available",
    "cloudformation": "available",
    "cloudwatch": "available",
... (remainder omitted) ...

Reference Sites

脚注
  1. Screenshots were taken in Portable mode ↩︎

  2. If "docker-vm.local" does not appear, please check if you can "ssh login". ↩︎

  3. This only appears the first time ↩︎

  4. It will not be displayed if the Docker daemon is not running on Ubuntu ↩︎

Discussion