0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

商用でも無料でDockerを使う方法(Windows 11)

Posted at

概要:

Docker Desktopを使わず、WSL2のUbuntuにDocker CLIとDocker Engineを直接インストールすることで、完全に無料でDockerを利用できます。
これにより、Dockerのライセンス制限を回避しつつ、商用利用も可能になります。

手順(WSL2とUbuntu24.04のインストール)

  1. WSL2を有効化
    PowerShellを「管理者権限で」開いて以下を実行:

    wsl --install
    
  2. UbuntuなどのLinuxディストリビューションをインストール
    Microsoft Storeから「Ubuntu 22.04 LTS」などをインストール。
    インストール後、初回起動でユーザー名とパスワードを設定

  3. デフォルトのWSLディストリビューションの確認

    wsl -l -v
    NAME            STATE           VERSION
    * Ubuntu          Stopped         2
      Ubuntu-24.04    Running         2
    

    デフォルトでUbuntuが入っているとこういうときがある

  4. Ubuntu-24.04 を デフォルト に切り替える方法

    wsl --set-default Ubuntu-24.04
    

    今すぐ Ubuntu-24.04 を開く方法(1回限り)
    デフォルトにはせずに、今すぐ Ubuntu-24.04 を起動したいだけなら:

    wsl -d Ubuntu-24.04
    

手順(WSL2上のUbuntu 24.04 にDockerをインストール)

Ubuntu 24.04は比較的新しいバージョンなので、Docker公式の手順をベースに、動作確認済みの手順で進めます。

  1. パッケージの更新と必要パッケージのインストール

    sudo apt update
    sudo apt upgrade -y
    sudo apt install -y ca-certificates curl gnupg lsb-release
    
  2. Docker公式GPG鍵の追加

    sudo install -m 0755 -d /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
      sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    sudo chmod a+r /etc/apt/keyrings/docker.gpg
    
  3. Dockerリポジトリを追加

    echo \
      "deb [arch=$(dpkg --print-architecture) \
      signed-by=/etc/apt/keyrings/docker.gpg] \
      https://download.docker.com/linux/ubuntu \
      $(lsb_release -cs) stable" | \
      sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
  4. Dockerのインストール

    sudo apt update
    sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    
  5. Dockerサービスの起動(WSL内で)

    sudo install -m 0755 -d /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
      sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    sudo chmod a+r /etc/apt/keyrings/docker.gpg
    
  6. sudoなしでdockerコマンドを使いたい場合(オプション)

    sudo usermod -aG docker $USER
    
  7. 動作確認

    docker --version
    docker run hello-world
    

    Hello from Docker! と表示されれば成功です 🎉

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?