0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DevContainerを利用したVSCodeでClineがコマンドの実行結果を参照出来るようにする

Last updated at Posted at 2025-04-15

はじめに

Clineはタスクの中でVSCodeのターミナルでのコマンドの実行・結果の参照が出来ます。
これをDocker+DevContainerを利用したVSCode上で試したところ失敗してしまったので、成功するまでの手順を記載します。

失敗原因

失敗原因はClineも教えてくれており、PowerShellを利用する必要があるためでした。
対象のDevContainerはAlpine Linuxであるため、デフォルトではPowershellは入っていません。

DevContainerのリポジトリに、PowerShellをインストールするためのスクリプトがあったのですが、これはDebian Linux向けでした。

今回はAlpine Linuxなので上記のスクリプトをそのまま使うことは出来ません。
そのため、今回はDockerfileにインストールコマンドを追加して自前でセットアップしていきます。

対応手順

1. PowerShellをインストールするスクリプトを作成

Debian向けの例のようにスクリプトファイルを作成し、実行する方式にすることにしました。
PowerShellのインストールスクリプトは公式にAlpine LinuxへのPowerShellのインストールがあるため、こちらを参考にします。

# Alpine Linux への PowerShell のインストール
# https://learn.microsoft.com/ja-jp/powershell/scripting/install/install-alpine?view=powershell-7.5

# install the requirements
sudo apk add --no-cache \
    ca-certificates \
    less \
    ncurses-terminfo-base \
    krb5-libs \
    libgcc \
    libintl \
    libssl3 \
    libstdc++ \
    tzdata \
    userspace-rcu \
    zlib \
    icu-libs \
    curl

apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache \
    lttng-ust \
    openssh-client \

# Download the powershell '.tar.gz' archive
curl -L https://github.com/PowerShell/PowerShell/releases/download/v7.5.0/powershell-7.5.0-linux-musl-x64.tar.gz -o /tmp/powershell.tar.gz

# Create the target folder where powershell will be placed
sudo mkdir -p /opt/microsoft/powershell/7

# Expand powershell to the target folder
sudo tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7

# Set execute permissions
sudo chmod +x /opt/microsoft/powershell/7/pwsh

# Create the symbolic link that points to pwsh
sudo ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh

# Start PowerShell
pwsh

こちらをプロジェクトカレントの.devcontainer/library-scriptsフォルダに配置しました。

2. Dockerfileでスクリプトを呼び出す

1で作成したスクリプトをDockerfileで呼び出します。

FROM node:22-alpine

COPY .devcontainer/library-scripts/install-powershell.sh /tmp/library-scripts/

RUN apk add sudo &&\
    ash /tmp/library-scripts/install-powershell.sh

3. docker-compose build

ビルドします。

4. docker-compose up

upします。
個人的にはここでハマってしまい、DockerDesktop上で▶を押しても反映されず、upし直す必要がありました。

5. VSCodeをDevContainerで開いてPowerShellを選択

VSCodeをDevContainerで開きます。
Ctrl+Shift+Pでコマンドパレットを開き、Select Default Profileを選択します。
すると、shashなどと一緒に、pwshがあると思うので、pwshを選択します。

6. 試す!

これで設定は完了です。
適当なプロンプトで実行結果の取得を試してみます。

`ls`コマンドを実行して、その結果を教えて。

ちなみに、jestやvitestなどでテスト結果を参照して欲しい時などは、Watchモードにならないように--runオプションを付与するなどする必要があります。

おわりに

これで、DevContainerを利用したVSCodeでClineがコマンドの実行結果を参照出来るようになりました。
Debian向けのスクリプトやAlpineへのPowerShellインストール方法など、公式でのドキュメントがそれぞれ見つかったので助かりました。
これでCline君ともっと戯れていきたいと思います!
より良い方法などがあれば教えていただけると助かります。
ここまで見ていただきありがとうございました。

0
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?