Web制作、Web開発の歩き方

サーバー、データベース、インフラに関するトピックス

■第23話:Docker Desktop無しでDocker環境を構築する方法

(最終更新日:2025.06.15)

NoSQLのイメージ
この記事は3分で読めます!
(絵が小さい場合はスマホを横に)

「Docker Desktop無しでDocker環境を作ろう」

2021年以降、Docker Desktopは企業利用で有料化された。 コストやライセンスの観点から、WSL(Windows Subsystem for Linux)2上に直接Dockerをインストールして運用するケースが増えている。 本記事では、Docker Desktopを使わずに、WSL2(Ubuntu)上にDocker + Compose v2環境を構築する手順を紹介する。

マルチコンテナ


1.前提条件の確認

前提条件として、WSL2が正しくインストールされていることが必要だ。 WSL2が未導入の方は、以下のMicrosoft公式サイトの手順(https://learn.microsoft.com/ja-jp/windows/wsl/install)に従って、まずは導入してほしい。

  1. Windows11がインストールされている
  2. WSL2が有効化されている
  3. Ubuntu22.04LTSか24.04LTSがWSL上にインストールされている
  4. インターネット環境に接続されている
2.WSL2上にDockerをインストールする

まず、依存パッケージのインストールを行う。 これにより、 Docker公式サイトからパッケージを安全にダウンロードできるようになる。 lsb-releaseでは、Ubuntuのバージョンに合った情報を取得している。

依存パッケージのインストール

依存パッケージのインストール

次に公式GPG鍵とリポジトリの追加を行う。GPC鍵はリポジトリの署名検証に使われ、信頼されたDockerパッケージを使用することができる。 最近、セキュリティ強化のために必要になったものである。

Docker公式GPG鍵とリポジトリの追加

Docker公式GPG鍵とリポジトリの追加

次に、docker-composeなど必要なツールをインストールする。これにより、dockerを快適に使用することができる。

Docker本体のインストール

Docker本体のインストール

最後に、dockerコマンドに現在のユーザーをグループに加え、sudo無しで実行できるようにする。

現ユーザーをグループに追加

現ユーザーをグループに追加

以上のコマンドを順番に実行することで、Docker Desktop無しにWindowsでdockerを使うことができる。

3.docker-compose(v2)の使い方

Docker v2以降、docker compose(スペースあり)としてCompose機能が標準搭載されている。 古い docker-compose(ハイフンあり)は不要で、docker compose コマンドで全てを賄える。

docker-composeコマンド

docker-composeコマンド

4.Dockerデーモンを起動する方法

Ubuntu 22.04 以降のWSL環境では systemd がサポートされている。 systemdが有効なら、次のようにDockerを起動できる。

docker startコマンド

dockerを起動する2つのコマンド

そして、dockerが起動できていれば、docker runコマンドが上手く動くはずだ。 hello-worldを実行することで、以下のような返答があれば成功だ。

docker startコマンド

dockerの起動確認

これができたら、docker-compose.ymlファイルを用意して、docker composeコマンドが動くか確認しよう。 下記のファイルの場合、ブラウザで http://localhost:8080 にアクセスできれば成功だ。 下記のようなnginxのdocker-compose.ymlでなくとも、自前のファイルがあれば、それを実行して試してほしい。

docker composeの実行

docker composeの実行

5.まとめ

Docker Desktopを使わずにWSL2上に直接Docker環境を構築すれば、企業でもコストを抑えて運用できる。 そして、Compose v2は「docker compose」でシンプルに利用できる。 systemdが有効なWSL2環境であれば、起動管理も安定に行える。 今回紹介した構成は、軽量かつ柔軟なDocker環境で、ローカル開発環境としては非常に有用だ。 ぜひ、活用していこう。


▼参考図書、サイト

   doceker  docker 公式サイト


Topics on Servers, Databases, and Infrastructure ■Episode 23: How to Set Up a Docker Environment Without Docker Desktop (Last updated: 2025.06.15) NoSQL Image This article takes just 3 minutes to read! (If the image is too small, try rotating your phone) “Let’s set up Docker without Docker Desktop” Since 2021, Docker Desktop has required a paid license for corporate use. To save on costs and avoid licensing concerns, many are now installing Docker directly on WSL2 (Windows Subsystem for Linux). This article provides a step-by-step guide for setting up Docker + Compose v2 on WSL2 (Ubuntu) without using Docker Desktop. Multi-container Image [Table of Contents] Check Prerequisites How to Install Docker on WSL2 Using docker-compose (v2) How to Start the Docker Daemon Summary 1. Check Prerequisites Before you begin, make sure WSL2 is properly installed. If you haven't set up WSL2 yet, follow the instructions on the official Microsoft site: https://learn.microsoft.com/en-us/windows/wsl/install Windows 11 is installed WSL2 is enabled Ubuntu 22.04 LTS or 24.04 LTS is installed on WSL You have an internet connection 2. Install Docker on WSL2 First, install the required dependencies. This ensures secure access to Docker packages from the official Docker website. The `lsb-release` package retrieves information compatible with your Ubuntu version. Install Dependencies Install Dependencies Next, add the official Docker GPG key and repository. The GPG key is used to verify repository signatures, ensuring you're using trusted Docker packages. This step is now required due to recent security enhancements. Add Docker GPG Key and Repository Add Docker GPG Key and Repository Then, install Docker and related tools like `docker-compose`. These tools make working with Docker easier and more efficient. Install Docker Install Docker Finally, add your current user to the `docker` group so you can run Docker without using `sudo`. Add User to Docker Group Add User to Docker Group By following the above steps, you can use Docker on Windows without Docker Desktop. 3. Using docker-compose (v2) From Docker v2 onwards, `docker compose` (with a space) is included as a built-in feature. The old `docker-compose` (with a hyphen) is no longer needed. You can handle everything with the new `docker compose` command. docker-compose Command docker-compose Command 4. How to Start the Docker Daemon WSL with Ubuntu 22.04 or later now supports `systemd`. If `systemd` is enabled, you can start Docker using the following commands. Start Docker Command Two Ways to Start Docker Once Docker is running, try executing `docker run hello-world`. If you receive the expected output, your setup is successful. Docker Hello World Verify Docker is Running If everything works, try preparing a `docker-compose.yml` file and running `docker compose`. If you're using the sample file shown below, you should be able to access http://localhost:8080 in your browser. Alternatively, use your own project’s `docker-compose.yml` file if you have one. Running docker compose Running docker compose 5. Summary Setting up Docker directly on WSL2 without Docker Desktop helps reduce costs and licensing concerns for companies. With Compose v2, you can use `docker compose` easily and intuitively. If `systemd` is enabled in your WSL2 environment, service management is also stable. The structure introduced here offers a lightweight and flexible Docker setup, ideal for local development environments. Give it a try and make the most of it! ▼References    Docker Official Site