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?

WSLでのDocker Desktop+Laravel Sail環境構築でよくあるエラーと解決案

Last updated at Posted at 2025-06-17

目次

Docker Desktop起動時のエラー

Docker Desktop起動時のエラー2

Laravel Sailプロジェクト起動時のエラー

Docker Desktop起動時のエラー


スクリーンショット (5).png
上記のエラーは、VScodeでリモートウインドウ接続中にWSLが異常終了し、リモートウインドウ、VScode、Docker Desktopを閉じ、その後Docker Desktopを起動しようとしたところ発生しました。

筆者はDocker Desktop、WSLの再起動で解消されました。

復旧手順

  • VScodeを閉じる

    1. VScodeでリモートウインドウを開いている状態から、左下角のWSL ~をクリック

    2. リモートウインドウのオプションが表示されたら、一番下のリモート接続を終了するをクリック

    3. ×ボタンでVScodeを閉じる


  • Docker Desktopを完全停止

    1. Docker Desktopの左下あたりにある ⁝ をクリック
    2. 表示されたウインドウ一番下のQuit Docker Desktopをクリック

  • Ubuntuを再起動

    PowerShellにて以下のコマンドを実行

    # WSLを終了
    wsl --shutdown
    
    # Ubuntuを再起動
    wsl -d Ubuntu-24.04
    
    # Ubuntuは使用しているバージョンで入力してください
    

  • Docker Desktopを起動

    Docker Desktopアプリを開くと、エラーが出ずに起動するはずです。

追記 2025.6.18

根本的に「そもそもなぜWSLが異常停止するのか」
原因が分かったので追記しておきます。

結論としてはDocker Desktopの設定の問題でした。

スクリーンショット (13).png

Docker Desktopの
設定 > Resource > Advanced
に移動すると、下部の方にResource Saverという機能があります。

これは何かというと、設定した時間コンテナが起動されていなかった場合に、リソース節約のためWSLとDockerがスリープするという機能です。

筆者はこれがデフォルトでの有効になっていたので、無効にしたところ…

リモートウインドウ起動中のWSLの異常停止が解消されました。
同様の症状でお悩みの方は、ぜひ確認してみてください!

Docker Desktop起動時のエラー2

エラー画面.png
VScodeのリモートウインドウ接続中にWSLが異常終了した際、WSLリモートウインドウ及びDocker Desktopを閉じず(Docker Desktopを停止せず)にPowerShellにてwsl --shutdownでWSLを完全停止。その後Docker Desktopを再起動しようとしたところ、このようなエラーが発生しました。

エラーメッセージに関して、以下のような記述があります。

このディストリビューションのインストール、アンインストール、または変換が進行中です。
エラー コード: Wsl/Service/RegisterDistro/0x8000000d
exit status 0xffffffff

0x8000000d(登録失敗)エラー
原因としては、WSLをDockerディストリビューションに再接続中(ディストリビューション登録中)にWSLを強制終了したことにより、登録操作が失敗。加えてリモートウインドウを開いていたことによりWSLサービスが矛盾状態になり、内部整合性エラーを起こした可能性が高いことが分かりました。

筆者はDocker Desktopディストリビューションのリセットで解消しました。

復旧手順

  • VScodeを閉じる

    1. VScodeでリモートウインドウを開いている状態から、左下角のWSL ~をクリック

    2. リモートウインドウのオプションが表示されたら、一番下のリモート接続を終了するをクリック

    3. ×ボタンでVScodeを閉じる


  • Docker Desktopを完全停止

    1. Docker Desktopの左下あたりにある ⁝ をクリック
    2. 表示されたウインドウ一番下のQuit Docker Desktopをクリック

  • WSLを強制終了

    Ubuntuにて以下のコマンドを実行

    # WSLを強制終了
    wsl --shutdown
    

  • ディストリビューション(Docker Desktop)を削除

    Ubuntuにて以下のコマンドを実行

    # WSLからDocker Desktopディストリビューションの登録を解除
    wsl --unregister docker-desktop
    

  • Windowsの再起動

    念のため再起動してください(WSL サービスのキャッシュを完全にクリアするため)。

  • Docker Desktopを起動

    Docker Desktopアプリを開くと、エラーが出ずに起動するはずです。

Laravel Sailプロジェクト起動時のエラー

 1   User:~/example-app$ ./vendor/bin/sail up -d
 2   WARN[0000] Found orphan containers ([example-app-phpmyadmin-1]) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
 3   [+] Running 5/6
 4    ✔ Container example-app-meilisearch-1   Started                                                       1.8s
 5    ✔ Container example-app-mailpit-1       Started                                                       1.7s
 6    ✔ Container example-app-selenium-1      Started                                                       1.9s
 7    ⠸ Container example-app-mysql-1         Starting                                                      1.9s
 8    ✔ Container example-app-redis-1         Started                                                       1.9s
 9    ✔ Container example-app-laravel.test-1  Recreated                                                     0.5s
 10   Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu-24.04/fb139d1d59753ad93385147c866611a341aaa1d87343c7066a92b81eb2b6eef0" to rootfs at "/docker-entrypoint-initdb.d/10-create-testing-database.sh": create mountpoint for /docker-entrypoint-initdb.d/10-create-testing-database.sh mount: cannot create subdirectories in "/var/lib/docker/rootfs/overlayfs/4aac54ef1916d4e50561f05447dae8abc0abe5cc1cf62a29bc92d697bcd179a2/docker-entrypoint-initdb.d/10-create-testing-database.sh": not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

このエラーが出た経緯としては、LaravelSailでの環境構築にてcurl -s https://laravel.build/example-app | bashコマンドでプロジェクトを新規作成後、./vendor/bin/sail up -dコマンドでsailを実行しようとしたところエラーとなりました。
上記を見ていただくと、7行目のmysql-1のコンテナが起動しておらず、10行目でエラーメッセージが出ています。

10行目は少し長いですが、エラーメッセージ末尾の方に下記のような記述があります。

Are you trying to mount a directory onto a file (or vice-versa)? 
Check if the specified host path exists and is the expected type

これは、docker-compose.yml で ファイルとしてマウントしようとしているパスが、実際にはディレクトリだった(あるいはその逆) ためにエラーになっています。これはホストからのマウント対象が「以前の残骸」で不整合になっている典型的な症状です。
分かりやすく言うと、 以前作成したことのあるプロジェクトのDocker関連のボリューム・キャッシュ・マウント設定が残っていてそれが原因で不整合が起きている ことが考えられます。

筆者は、Dockerにて古いLaravel Sail関連のコンテナとボリュームを全て削除し、プロジェクトを新規作成し直したところエラーが解消しました。

復旧手順

  • Laravel Sailプロジェクトをリセットする

    Ubuntuにて以下のコマンドを実行
    # Ubuntuをアンインストール
    wsl --unregister Ubuntu-24.04
    
    # Ubuntuを再インストール
    wsl --install -d Ubuntu-24.04
    
    # Ubuntuは使用しているバージョンで入力してください
    

    この操作でUbuntu内のデータは消えます


  • Docker側のコンテナ、ボリュームも削除する

    Ubuntuにて以下のコマンドを実行
    docker stop $(docker ps -aq)
    docker rm $(docker ps -aq)
    docker volume prune -f
    docker network prune -f
    
    ※ これで古い Laravel Sail 関連のコンテナとボリュームを全部削除できます。
    ※このコマンドが通らない方は、記事終盤の【補足2】をご参照ください

  • 改めて、Laravel Sailプロジェクトを作成

    Ubuntuにて以下のコマンドを実行
    # プロジェクト新規作成
    curl -s https://laravel.build/example-app | bash
    
    # 作成したプロジェクトディレクトリに移動
    cd example-app
    
    # プロジェクトを実行
    ./vendor/bin/sail up -d
    
    この時点でエラーが出なければ、環境はクリーンに整っています。


【 補足1 】なぜUbuntuの再インストールでは不十分なのか

WSL2 環境では、Ubuntu(Linux側)と Docker(Windows側)は別管理です。

  • Ubuntu を再インストールしても、Docker の設定やボリュームは Windows 側に残る
  • そのため、マウント設定や以前の volume 名などが原因でコンテナ起動に失敗する

【 補足2 】Docker側のコンテナ、ボリューム削除コマンドが通らない時

docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
docker volume prune -f
docker network prune -f

復旧手順の上記Dockerコマンドが通らないときの対処法を補足します。


1    User:~$ docker stop $(docker ps -aq)
2    docker rm $(docker ps -aq)
3    docker volume prune -f
4    docker network prune -f
5    permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.50/containers/json?all=1": dial unix /var/run/docker.sock: connect: permission denied
6    docker: 'docker stop' requires at least 1 argument
7    
8    Usage:  docker stop [OPTIONS] CONTAINER [CONTAINER...]
9    
10   See 'docker stop --help' for more information
11   permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.50/containers/json?all=1": dial unix /var/run/docker.sock: connect: permission denied
12   docker: 'docker rm' requires at least 1 argument
13   
14   Usage:  docker rm [OPTIONS] CONTAINER [CONTAINER...]
15   
16   See 'docker rm --help' for more information
17   permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Head "http://%2Fvar%2Frun%2Fdocker.sock/_ping": dial unix /var/run/docker.sock: connect: permission denied
18   permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Head "http://%2Fvar%2Frun%2Fdocker.sock/_ping": dial unix /var/run/docker.sock: connect: permission denied

上記のようなエラーが出た場合、以下の問題にぶつかっています。


permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

5、11、17、18行目にて表示されている上記のようなメッセージの内容としては、現在のユーザーに Dockerを操作する権限がないというものです。

解決方法

  • 方法1:一時的な権限付与で良いならsudoを使う
    Ubuntuにて以下のコマンドを実行
    # Dockerコマンドの頭にsudoをつける
    sudo docker stop $(sudo docker ps -aq)
    sudo docker rm $(sudo docker ps -aq)
    sudo docker volume prune -f
    sudo docker network prune -f
    
    これで一時的な権限で実行できます。

  • 方法2:現在のユーザーを Docker グループに追加
    この方法で、毎回 sudo しなくても済むようになります

    Ubuntuにて以下のコマンドを実行

    # $USERには自分のユーザー名を入力
    sudo usermod -aG docker $USER
    

    その後、Ubuntuを再起動
    Ubuntuにて以下のコマンドを実行後、再度開き直してください

    exit
    

    sudo無しの以下のコマンドが通ればOK

    docker ps
    
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?