0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windowsでwsl + Dockerの環境構築

Posted at

wslの設定とインストール

wslの設定

検索バーで"Windowsの機能の有効化または無効化を検索し、
以下機能にチェックをつけてOKを押す
・Hyper-V
・仮想マシンプラットフォーム
・Linux用Windowsサブシステム

wslのインストール

コマンドプロンプトを管理者として実行

wslをインストール
wsl --install
wslをアップデート
wsl --update
ディストリビューションを確認
wsl --list --verbose
#or
wsl -l -v
Ubuntuをインストール
wsl --install -d Ubuntu
ディストリビューションの削除
wsl --unregister ディストリビューション名

VScodeでUbuntu起動

VScodeの拡張機能でDev ContainersまたはRemote Developmentをインストールする
VScode内にインストールした拡張機能からwslの仮想環境を起動する

Remote Developmentの場合
”リモートエクスプローラー”→”WSLターゲット"→"Ubuntu"→"現在のウィンドウで接続する"

Dockerの環境構築

https://docs.docker.com/engine/install/ubuntu/#installation-methods
VScodeからwsl/Ubuntuの仮想環境が起動していることを確認しターミナルを開く

Dockerインストールのリポジトリ登録
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
パッケージのインスール
#Install the Docker packages
 sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
実行中・停止中、両方のコンテナを表示
docker ps -a
or
docker ps -all
実行中のコンテナを表示
docker ps
コンテナを削除
docker rm <NAME>
Dockerのバージョン情報を表示
docker version
dockerのユーザー権限
#確認
getent group docker
#結果 docker: x :123:

#dockerグループにユーザーを追加する
sudo usermod -aG docker <ユーザー名>

getent group docker
#結果 docker: x :123: <ユーザー名>
dockerのユーザー権限:root以外のユーザーおよびsudoアクセス権を持つユーザーがDockerコマンドを実行できるようにする手順
# dockerグループを作成
groupadd docker

# dockerサービスを再起動します。
service docker restart
#UNIXソケット/var/run/docker.sockは、dockerグループのメンバーによって読取りと書込みが可能

#Dockerアクセス権限が必要なユーザーをdockerグループに追加
usermod -a -G docker user1

コンテナの作成

https://hub.docker.com/
https://hub.docker.com/_/python

コンテナを選択する

新しいコンテナの起動
#docker run <オプション> <イメージ> <コマンド>
#docker run -it --name test python:3.xx
docker run -it -v /mnt --name test python.3.12.8

オプション
-i コンテナの標準入力にアタッチ
-t 疑似ターミナルを割り当て
-v コンテナの任意のパスにますんと
--name コンテナに名前をつける

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?