2
2

More than 1 year has passed since last update.

Dockerを知らなくてもWindowsでLocalStackしたい!

Last updated at Posted at 2022-08-31

前書き

Windowsを使用していてDockerのことはよくわからないが、とりあえず素早くLocalStackを使ってみたいという方向けの手順です。(自己紹介)
自力でdocker-composeする場合と比べるとEnvironmentによる設定ができないため好みの動作にカスタマイズできませんが、
とりあえずは使えます。

前提条件

  • Windows11
  • Python 3.xがインストール済
  • awscliがインストール済
  • venvで仮想化しておいたほうがトラブルが少ないと思う

以下手順

1.Windowsの機能の有効化

Powershellコンソールを管理者で起動して下のコマンド実行する。
1コマンドで必要なものをすべてまとめて入れてくれる便利なコマンドです。
必要なものと今は必要ではないものが入るが、必要ではないものは気にしない。

wsl --install

コマンド実行後に再起動を求められたら再起動する。

2.Pythonパッケージ「localstack」をインストールする

とりあえず動かすには必須。

pip install localstack

3.Pythonパッケージ「awscli-local」をインストールする

pip install awscli-local

4.Docker Desktopインストール

ここの「Also available for Windows and Linux」のWindowsをクリックするとダウンロードできる
ダウンロードしたらダイアログの選択肢は変更せずにインストールする
再起動を求められなくても再起動をしたほうが良い

5.LocalStackのDockerイメージを用意する

下のコマンドを実行するとdocker hubからダウンロードしてDocker Desktopに登録されます。

docker pull localstack/localstack

6.LocalStack起動

localstack start -d

7.LocalStackで利用可能なAWSサービスを確認してみる

localstack status services

8.LocalStack用のCLIを実行してみる

awslocal ec2 describe-vpcs

9.LocalStack停止

localstack stop

10.終了

お疲れ様でした

トラブルシュート

自分の環境で発生したエラーと解消した方法を記載します。
誰でもこの方法で解決できるわけではないので参考情報としてご参照ください。

docker pullコマンドでプロキシに関するエラーメッセージが表示される

エラーメッセージ例

Error response from daemon: Get "https://registry-1.docker.io/v2/": Failed to lookup host: hogehoge

解決方法

自分の環境ではプロキシを使わずに直通なので以下のように設定して乗り切った。
Docker DesktopのSettingsを開く -> Resources -> Proxies -> Manual proxy configurationをOnにして、
WebServer等のテキストボックスは全て空にしておく。
その後右下の「Apply & Restart」ボタンを押す。

pip install localstackでパスに関する警告が出た

エラーメッセージ例

WARNING: The script cmark.exe is installed in 'C:\Users\username\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script tabulate.exe is installed in 'C:\Users\username\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script pysemver.exe is installed in 'C:\Users\username\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts pyrsa-decrypt.exe, pyrsa-encrypt.exe, pyrsa-keygen.exe, pyrsa-priv2pub.exe, pyrsa-sign.exe and pyrsa-verify.exe are installed in 'C:\Users\username\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script dotenv.exe is installed in 'C:\Users\username\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script pygmentize.exe is installed in 'C:\Users\username\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script pbr.exe is installed in 'C:\Users\username\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Running setup.py install for dill ... done
WARNING: The script chardetect.exe is installed in 'C:\Users\username\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

解決方法

下のコマンドを実行して「Location」に表示されたパスを環境変数PATHに追加する。

pip show localstack
原因?

Pythonをall usersでインストールしてあり、
localstackがuserにインストールされていることが原因か。

awslocalでエラーが出る

エラーメッセージ例

FileNotFoundError: [WinError 2] 指定されたファイルが見つかりません。

解決方法

awscliがインストールされていない場合に出た。
公式を参照してインストールする。

localstack start -dでnot recognizedエラーが出る

エラーメッセージ例

localstack: The term 'localstack' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

解決方法

下のコマンドを実行して「Location」に表示されたパスを環境変数PATHに追加する。

pip show localstack
2
2
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
2
2