5
4

More than 1 year has passed since last update.

Windows11Proのローカル環境(WSL2/Ubuntu/Docker/VS Code)構築からAWSのECRへプッシュ、ECSデプロイまで

Last updated at Posted at 2023-07-23

Windows11を購入しました。ローカルの開発環境を整え、
コンテナを実際にAWSで動かすところまでやってみた記録です。

はじめに

Windows11Pro+WSL2+Ubuntu+Docker環境を構築し、
VS CodeからUbuntuに接続しプログラム作成、コンテナイメージ作成、
AWSのECRへプッシュ、ECSへのデプロイ・接続確認までを行います。

  1. WSL2のインストール (今回の記事)
  2. Visual Studio CodeのインストールとUbuntu on WSL2への接続
  3. Docker Desktopのインストール、Dockerfile作成、コンテナビルドと修正
  4. AWS CLIインストール、IAMユーザー作成、アクセスキー作成、AWSリソースへのアクセス
  5. AWS ECRリポジトリ作成、Ubuntu on WSL2からECRへのプッシュ
  6. AWS ECSのタスク定義、クラスタ作成、サービス作成

WSL2のインストール

下記Microsoftのサイトを参考に、WSL2のインストールを実行します。

デフォルトではUbuntuがインストールされます。Ubuntuのまま進めます。

poweshell(管理者モード)
wsl --install

image.png

image.png

PS C:\Users\hiropon> wsl --install
インストール中: 仮想マシン プラットフォーム
仮想マシン プラットフォーム はインストールされました。
インストール中: Linux 用 Windows サブシステム
Linux 用 Windows サブシステム はインストールされました。
インストール中: Ubuntu
Ubuntu はインストールされました。
要求された操作は正常に終了しました。変更を有効にするには、システムを再起動する必要があります。
PS C:\Users\hiropon>

 
Womdowsを再起動します。
再起動が完了すると、Windowsターミナルが自動的に実行され、Ubuntuが起動されます。
初回なので、新規にユーザー名とパスワードを作成します。
image.png

下記のガイドに従って、登録します。
今回ユーザー名は「hiropon」としました。
適宜、ご自身の利用するユーザー名に読み替えてください。

Ubuntu は既にインストールされています。
Ubuntu を起動しています...
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: hiropon
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.90.1-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage


This message is shown once a day. To disable it please create the
/home/hiropon/.hushlogin file.
hiropon@um560xt:~$

パッケージの更新とアップデートを行います。

bash
sudo apt update && sudo apt upgrade

image.png
・・・略・・・
image.png

Ubuntuを再起動します。

bash
sudo reboot

再起動後は、スタートメニューから「Ubuntu」を起動、
もしくはWindowsターミナルを開いて、「Ubuntu」を選択します。
image.png
image.png

さいごに

WSL2のインストール、Ubuntuのアップデート・再起動、WindowsコンソールからUbuntuへの接続が完了しました。
次回は、VS Codeをインストールし、VS CodeからUbuntuに接続します。

参考ページ

5
4
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
5
4