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-desktopを使わずにWindowsでdockerを使う

Last updated at Posted at 2025-07-03

概要

ついにうちの会社も、dockerを導入してもいいかも...?という波が来ました。
お家ではがっつり使ってましたが、これでIaCでの環境構築、PoCなどなどいろんなことが楽になる...!

が、なんとDocker-Desktopのホームページにこんな一文が

image.png

のでここでは、Docker-Desktopを使わず、なるべく楽にWindows環境でDocker導入までやってきます。

やること

  1. WSL2の導入
  2. WSL2上にDockerEngineのインストール(docker-composeなどのプラグインも)
  3. dockerコマンドをsudo以外でも使えるようにグループに追加
  4. 動作確認
  5. (オマケ)WSL2起動時にDockerEngineを自動起動

1. WSL2の導入

PowerShellで以下のコマンドを打つだけ。めちゃくちゃお手軽ですね。windows10だともうちょっと設定が必要な気がしますが、windows11だとかなり簡単に導入できるようになっていたと思います。

wsl --install

また、適当なLinuxイメージをインストールしておくといいです。私はMicrosoft StoreからUbuntuをインストールしました。

2. WSL2上にDockerEngineのインストール

WSL2上のターミナルで下記コマンドを打ち、インストール&実行までやっちゃいましょう。

curl -fsSL https://get.docker.com | sh

ちなみに以下のような感じで、勝手にいろいろ行ってバージョン確認までしてくれました。
docker-composeなどのプラグインも勝手に入ってくれた模様です。

+ sudo -E sh -c DEBIAN_FRONTEND=noninteractive apt-get -y -qq install ca-certificates curl >/dev/null
+ sudo -E sh -c install -m 0755 -d /etc/apt/keyrings
+ sudo -E sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" -o /etc/apt/keyrings/docker.asc
+ sudo -E sh -c chmod a+r /etc/apt/keyrings/docker.asc
+ sudo -E sh -c echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu noble stable" > /etc/apt/sources.list.d/docker.list
+ sudo -E sh -c apt-get -qq update >/dev/null
+ sudo -E sh -c DEBIAN_FRONTEND=noninteractive apt-get -y -qq install docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin >/dev/null
+ sudo -E sh -c docker version
Client: Docker Engine - Community
 Version:           28.3.1
 API version:       1.51
 Go version:        go1.24.4
 Git commit:        38b7060
 Built:             Wed Jul  2 20:56:27 2025
 OS/Arch:           linux/amd64
 Context:           default

3. dockerコマンドをsudo以外でも使えるようにグループに追加

このままだと、sudoユーザでないとdocker使えないらしい状態です。ので、dockerグループにログイン中のユーザを追加してあげましょう。

sudo usermod -aG docker $USER

ログイン中のユーザはすぐに変更適用されないので、一度再起動しておいてください。

sudo reboot

また、再起動するとdockerエンジンは自動で起動しないので、次のコマンドでdockerを起動することを忘れないでおいてください。

sudo service docker start

4. 動作確認

動作確認に便利なhello-worldコンテナを起動してみましょう。

docker run hello-world

こんな感じで実行できれば完璧!

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

以下のエラーで起動できない方は

Unable to find image 'hello-world:latest' locally
docker: error getting credentials - err: exec: "docker-credential-desktop.exe": executable file not found in $PATH, out: ``

Run 'docker run --help' for more information

credentialsのファイル回りでエラーが起こっているみたいなので、以下のコマンドで一回リセットしてあげましょう。

# docker認証設定をクリア
rm -f ~/.docker/config.json
# ディレクトリを確認&作り直し
mkdir -p ~/.docker
# 設定ファイル作成
echo '{}' > ~/.docker/config.json

5.(オマケ)WSL2起動時にDockerEngineを自動起動

WSL2起動時に毎回docker立ち上げるの面倒なので、systemctlに登録しておきましょう。
これでdockerエンジンが自動起動してくれます。

sudo systemctl enable 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?