1
1

More than 1 year has passed since last update.

[VScode_Remote Containers] コンテナ環境内でデバッグする(Mac)

Posted at

リポジトリ

https://github.com/melumuccu/python-openpyxl

概要

この記事でやれること

  • VScodeの Remote Containers を使ったローカル環境を一切汚さずデバッグができる環境を作れる

環境

バージョン memo
Python 3.10.4
OpenPyXL 3.0.9 Excel ファイルを Python で扱うためのパッケージ
Docker 20.10.11
Visual Studio Code 1.66.2
Remote Containers 0.234.0 VScode 拡張。コンテナ内で VScode を動作させる(?)。デバッグなどの目的で導入。

環境構築

前提環境: 前記事を利用

[Python×Docker×OpenPyXL] Excelファイルを扱うDocker環境構築(Mac) - Qiita

  • 上記記事のdocker run コマンドが正常に動作する前提とします

VScodeにRemote Containers拡張機能を導入

  • 識別子: ms-vscode-remote.remote-containers

Remote Containersの設定

  • .devcontainer/devcontainer.json にDockerfileのパスやコンテナ内のVScodeにインストールする拡張機能などを指定
    • 前提環境では下記のようになっている
{
  "name": "Python IO",
  // Dockerfileでイメージ・コンテナを作成
  "dockerFile": "../Dockerfile",
  // リモート先のVS Codeにインストールする拡張機能
  "extensions": [
    // Python系
    "ms-python.python",
    "ms-python.vscode-pylance",
    "kevinrose.vsc-python-indent",
    "dongli.python-preview",
    "njpwerner.autodocstring",
    // その他Util
    "nemesv.copy-file-name"
  ],
}
  • 下記は必須(デバッグ実行に必要なはず)
    • "ms-python.python"
    • "ms-python.vscode-pylance"

Remote Development でコンテナに入る

  • 下記画像の順にクリック
    • (VScodeの左下にあるボタン)

RemoteDevelopment_1.png

---

RemoteDevelopment_2.png

---

RemoteDevelopment_3.png

sample.py を開き VScode から実行する

  • 実行のみでも、ソースの行をクリックしてブレークポイントを仕掛けてデバッグ実行でも

Untitled.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1