Closed17

Docker Desktopの「Command failed」エラーへの対応

事象

Docker Desktopでコンテナの起動や削除をしようとすると、
「"Command failed"」エラーが発生して、起動できない。

目的

このコンテナはもう使わないので削除したい。

思い当たる節

思い当たる節は、昨日このコンテナで利用してたRailsTutorialというディレクトリを、RailsTutorial_toyappに変更したことだ。
エラーの内容を詳しくもう少し確認してみる。

エラー全文(読みやすく整形済み)

エラー全文を見ると、Dockerを起動できなかった理由は、コマンド"wsl~"が失敗したからで、それは、指定したファイルが見つからなかったと書いてある。
そこで、"wsl~"コマンドがどんなファイルを指定していたのかを調べる。

Cannot start Docker Compose application. Reason: 
Command failed: wsl -d Ubuntu -e sh -c "cd \"/home/masa/environment/RailsTutorial\" && docker-compose --project-directory \"/home/masa/environment/RailsTutorial\" up -d" 
[3816] Failed to execute script docker-compose Traceback (most recent call last): 
  File "urllib3/connectionpool.py",line 677, in urlopen 
  File "urllib3/connectionpool.py", line 392, in _make_request 
  File "http/client.py", line 1252, in request 
  File "http/client.py", line 1298, in _send_request 
  File "http/client.py", line 1247, in endheaders 
  File "http/client.py", line 1026, in _send_output 
  File "http/client.py", line 966, in send 
  File "docker/transport/unixconn.py", line 43, in connect 

FileNotFoundError: 
[Errno 2] No such file or directory During handling of the above exception, 
another exception occurred: 
Traceback (most recent call last): 
  File "requests/adapters.py", line 449,in send 
  File "urllib3/connectionpool.py", line 727, /rin urlopen 
  File "urllib3/util/retry.py", line 403,in increment 
  File "urllib3/packages/six.py", line 734,in reraise 
  File "urllib3/connectionpool.py", line 677,in urlopen 
  File "urllib3/connectionpool.py", line 392,in _make_request 
  File "http/client.py", line 1252,in request 
  File "http/client.py", line 1298,in _send_request 
  File "http/client.py", line 1247,in endheaders 
  File "http/client.py", line 1026,in _send_output 
  File "http/client.py", line 966,in send 
  File "docker/transport/unixconn.py", line 43,in connect urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')) During handling of the above exception, another exception occurred: Traceback (most recent call last): 
  File "docker/api/client.py", line 205,in _retrieve_server_version 
  File "docker/api/daemon.py", line 181,in version 
  File "docker/utils/decorators.py", line 46,in inner 
  File "docker/api/client.py", line 228,in _get 
  File "requests/sessions.py", line 543,in get 
  File "requests/sessions.py", line 530,in request 
  File "requests/sessions.py", line 643,in send 
  File "requests/adapters.py", line 498,in send requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')) During handling of the above exception, another exception occurred: Traceback (most recent call last): 
  File "bin/docker-compose", line 3,in <module> 
  File "compose/cli/main.py", line 67,in main 
  File "compose/cli/main.py", line 123,in perform_command 
  File "compose/cli/command.py", line 69,in project_from_options 
  File "compose/cli/command.py", line 132,in get_project 
  File "compose/cli/docker_client.py", line 43,in get_client 
  File "compose/cli/docker_client.py", line 170,in docker_client 
  File "docker/api/client.py", line 188,in __init__ 
  File "docker/api/client.py", line 213,in _retrieve_server_version docker.errors.DockerException: 

Error while fetching server API version: 
('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

"wsl~"コマンドがどんなファイルを指定していたのかを調べる。

コマンドを整形。

wsl -d Ubuntu -e sh -c 
  "cd \"/home/masa/environment/RailsTutorial\" && 
  docker-compose --project-directory \"/home/masa/environment/RailsTutorial\" up -d" [3816] 

見ているディレクトリは。/home/masa/environment/RailsTutorial
現在の開発環境のディレクトリには、上記ディレクトリはあるが、それは昨日作成したものなので、うまくいってないと思われる。

masa@DESKTOP-0CNPS43:~/environment$ ls -l
合計 8
drwxr-xr-x 16 masa masa 4096  16 14:55 RailsTutorial
drwxr-xr-x 17 masa masa 4096  16 09:48 RailsTutorial_toyapp

ここで自分が考えられる解決策は、2つ。

  1. 昨日リネームしたファイルをもう一度戻し、削除を行う。
  2. 強制的に削除を行う。

①なら削除できそうだが、②についても調べてみて、②が難しそうであれば、①で行うことにする。

②強制的に削除を行う方法について調べる。

docker compose command failed」、
docker desktop command failed」、
Cannot start Docker Compose application
といったワードで検索してみたが、よさそうな記事は見つからなかった。

そもそも自分がDocker Desktop上の"RailsTutorial"を削除したい理由は、昨日開発環境に作った"RailsTutorial"のコンテナを作りたいという目的だ。
なので、ここで、"docker-compose build"をしてどうなるかを試してみる。
と、エラーが出てきたので、それを確認する。

"docker-compose build"のエラー確認

エラー全文

masa@DESKTOP-0CNPS43:~/environment/RailsTutorial$ docker-compose build
Traceback (most recent call last):
  File "urllib3/connectionpool.py", line 677, in urlopen
  File "urllib3/connectionpool.py", line 392, in _make_request
  File "http/client.py", line 1252, in request
  File "http/client.py", line 1298, in _send_request
  File "http/client.py", line 1247, in endheaders
  File "http/client.py", line 1026, in _send_output
  File "http/client.py", line 966, in send
  File "docker/transport/unixconn.py", line 43, in connect
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "requests/adapters.py", line 449, in send
  File "urllib3/connectionpool.py", line 727, in urlopen
  File "urllib3/util/retry.py", line 403, in increment
  File "urllib3/packages/six.py", line 734, in reraise
  File "urllib3/connectionpool.py", line 677, in urlopen
  File "urllib3/connectionpool.py", line 392, in _make_request
  File "http/client.py", line 1252, in request
  File "http/client.py", line 1298, in _send_request
  File "http/client.py", line 1247, in endheaders
  File "http/client.py", line 1026, in _send_output
  File "http/client.py", line 966, in send
  File "docker/transport/unixconn.py", line 43, in connect
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "docker/api/client.py", line 205, in _retrieve_server_version
  File "docker/api/daemon.py", line 181, in version
  File "docker/utils/decorators.py", line 46, in inner
  File "docker/api/client.py", line 228, in _get
  File "requests/sessions.py", line 543, in get
  File "requests/sessions.py", line 530, in request
  File "requests/sessions.py", line 643, in send
  File "requests/adapters.py", line 498, in send
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bin/docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 67, in main
  File "compose/cli/main.py", line 123, in perform_command
  File "compose/cli/command.py", line 69, in project_from_options
  File "compose/cli/command.py", line 132, in get_project
  File "compose/cli/docker_client.py", line 43, in get_client
  File "compose/cli/docker_client.py", line 170, in docker_client
  File "docker/api/client.py", line 188, in __init__
  File "docker/api/client.py", line 213, in _retrieve_server_version
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
[9406] Failed to execute script docker-compose

またしてもファイルが見つからないエラー。
http/client.py docker compose 」で検索すると、
"systemctl start docker" で解決しそう。

systemctlはsystemdを操作するコマンドで、サービスの起動や停止、状態確認などを行うことができる。

masa@DESKTOP-0CNPS43:~/environment/RailsTutorial$ sudo systemctl start docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: ホストが落ちています

ホストが落ちているので失敗。
リスナーの方から、「DockerのFactory Reset(初期化)」を初期化してはどうかとのことで、実行する。

参考

Github『Errors running up』

DockerのFactory Reset(初期化)

Docker Desktopの虫マークから実行。

起動すると、コンテナもきれいさっぱりなくなりました。

コンテナがきれいになくなったので、"docker-compose build"を実行してみる。

"docker-compose build"を実行してみる。

masa@DESKTOP-0CNPS43:~/environment/RailsTutorial$ docker-compose build
postgres uses an image, skipping
redis uses an image, skipping
Building web
Traceback (most recent call last):
  File "bin/docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 67, in main
  File "compose/cli/main.py", line 126, in perform_command
  File "compose/cli/main.py", line 302, in build
  File "compose/project.py", line 468, in build
  File "compose/project.py", line 450, in build_service
  File "compose/service.py", line 1125, in build
  File "docker/api/build.py", line 261, in build
  File "docker/api/build.py", line 308, in _set_auth_headers
  File "docker/auth.py", line 301, in get_all_credentials
  File "docker/auth.py", line 287, in _get_store_instance
  File "docker/credentials/store.py", line 25, in __init__
docker.credentials.errors.InitializationError: docker-credential-desktop.exe not installed or not available in PATH
[19406] Failed to execute script docker-compose

一番下のエラーを見ると、docker-credential-desktop.exeインストールされていないか、パスが通っていませんとある。
そこで、"echo $PATH"でパスを調べる。

"echo $PATH"でパスを調べる。

"echo $PATH"でパスを調べると、確かにdockerに関するパスがなかった。

masa@DESKTOP-0CNPS43:~/environment/RailsTutorial$ echo $PATH
/home/masa/.rbenv/shims
/home/masa/.rbenv/bin
/home/masa/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/bin
/home/masa/.rbenv/shims
/home/masa/.rbenv/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/iCLS/
/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/iCLS/
/mnt/c/Windows/system32
/mnt/c/Windows
/mnt/c/Windows/System32/Wbem
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/
/mnt/c/Windows/System32/OpenSSH/
/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/DAL
/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/DAL
/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/IPT
/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/IPT
/mnt/c/Program Files/Git/cmd
/mnt/c/Program Files/nodejs/
/mnt/c/Ruby27-x64/bin
/mnt/c/Users/masa/AppData/Local/Microsoft/WindowsApps
/mnt/c/Program Files/JetBrains/PyCharm Community Edition 2020.2.3/bin
/mnt/c/Users/masa/AppData/Local/Programs/Microsoft VS Code/bin
/mnt/c/Users/masa/AppData/Roaming/npm
/mnt/c/Program Files/heroku/bin
/mnt/c/Program Files/vim/vim81-kaoriya-win64
/snap/bin

なので、環境変数を追加する。

参考

docker-credential-desktop.exe not installed or not available in PATH

環境変数を追加

下記コマンドで、Dockerのパスを環境変数に追加する。

echo 'export PATH="$PATH:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin"' >> ~/.profile

コマンド実行。

masa@DESKTOP-0CNPS43:~/environment/RailsTutorial$ echo 'export PATH="$PATH:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/Prog ~/.profile
masa@DESKTOP-0CNPS43:~/environment/RailsTutorial$ tail ~/.profile
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi
export PATH="$PATH:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin"

これでパスが通ったはず。
なので、再度"docker-compose build"を実行する。

参考

WSL2上のdocker-composeで認証エラー

再度"docker-compose build"を実行。

再度"docker build"を実行すると、同じエラー。

asa@DESKTOP-0CNPS43:~/environment/RailsTutorial$ docker-compose build
postgres uses an image, skipping
redis uses an image, skipping
Building web
Traceback (most recent call last):
  File "bin/docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 67, in main
  File "compose/cli/main.py", line 126, in perform_command
  File "compose/cli/main.py", line 302, in build
  File "compose/project.py", line 468, in build
  File "compose/project.py", line 450, in build_service
  File "compose/service.py", line 1125, in build
  File "docker/api/build.py", line 261, in build
  File "docker/api/build.py", line 308, in _set_auth_headers
  File "docker/auth.py", line 301, in get_all_credentials
  File "docker/auth.py", line 287, in _get_store_instance
  File "docker/credentials/store.py", line 25, in __init__
docker.credentials.errors.InitializationError: docker-credential-desktop.exe not installed or not available in PATH
[22656] Failed to execute script docker-compose

環境変数の反映は再起動後とのことなので、WSLのUbuntuを再起動する。

WSLのUbuntuを再起動

"wsl --shutdown" wslをシャットダウン。
その後、自動で起動。

C:\Users\masa>wsl --shutdown

再び、"docker-compose build"を実行。

masa@DESKTOP-0CNPS43:~/environment/RailsTutorial$ docker-compose build

The command 'docker-compose' could not be found in this WSL 2 distro.
We recommend to activate the WSL integration in Docker Desktop settings.

See https://docs.docker.com/docker-for-windows/wsl/ for details.

Docker DesktopのWSL統合がアクティベート化されていないとのこと。
確認すると、UbuntuのアクティベートがOFFになっていたので、ONにする。
(おそらく、Docker Desktopを初期化したときにOFFになったと思われる。)

Docker DesktopのWSL統合をアクティベート化

Docker DesktopのWSL統合をUbuntuも有効にする。

再度、"docker-compose build"を実行。

masa@DESKTOP-0CNPS43:~/environment/RailsTutorial$ docker-compose build

The command 'docker-compose' could not be found in this WSL 2 distro.
We recommend to activate the WSL integration in Docker Desktop settings.

See https://docs.docker.com/docker-for-windows/wsl/ for details.

同じエラー。
Docker Desktopを再起動して、再度コマンドを打つ。

Docker Desktopを再起動

画面右下からDocker Desktopを終了。

Docker Desktopを再起動後、WSLも有効化になっていることも確認し、

"docker-compose build"を実行。
subprocess.CalledProcessError」エラーが発生、それを確認する。

「subprocess.CalledProcessError」エラーの確認

"docker-compose build"の実行時の出力

masa@DESKTOP-0CNPS43:~/environment/RailsTutorial$ docker-compose build
postgres uses an image, skipping
redis uses an image, skipping
Building web
Traceback (most recent call last):
  File "docker/credentials/store.py", line 80, in _execute
  File "subprocess.py", line 411, in check_output
  File "subprocess.py", line 512, in run
subprocess.CalledProcessError: Command '['/mnt/c/Program Files/Docker/Docker/resources/bin/docker-credential-desktop.exe', 'list']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bin/docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 67, in main
  File "compose/cli/main.py", line 126, in perform_command
  File "compose/cli/main.py", line 302, in build
  File "compose/project.py", line 468, in build
  File "compose/project.py", line 450, in build_service
  File "compose/service.py", line 1125, in build
  File "docker/api/build.py", line 261, in build
  File "docker/api/build.py", line 308, in _set_auth_headers
  File "docker/auth.py", line 302, in get_all_credentials
  File "docker/credentials/store.py", line 71, in list
  File "docker/credentials/store.py", line 93, in _execute
docker.credentials.errors.StoreError: Credentials store docker-credential-desktop.exe exited with "error listing credentials - err: exec: "docker-credential-wincred.exe": executable file not found in %PATH%, out: ``".
[3181] Failed to execute script docker-compose

うーん、これ以上これらエラーに対して時間を割くのは無駄に思えてきたので、WSLのUbuntuを初期化する。

WSLのUbuntuを初期化

Windowsの設定画面でリセットを実行。

参考サイトにはリセットで初期化できると書いてあったが、リセット後にUbuntuが起動しなくなったので、アンインストールして、再インストールする。

参考

Windows 10のWSL環境を初期化してクリーンな状態に戻す

Ubuntuの再インストール

こちらにてUbuntuを再インストール。
ディレクトリ等作成後、"docker-compose build"を実行すると、またしてもエラーがでてきた。

masa@DESKTOP-0CNPS43:~$ mkdir environment
masa@DESKTOP-0CNPS43:~$ ls
environment
masa@DESKTOP-0CNPS43:~$ cd environment/
masa@DESKTOP-0CNPS43:~/environment$ git clone https://github.com/MASA20201203/RailsTutorial.git
Cloning into 'RailsTutorial'...
remote: Enumerating objects: 191, done.
remote: Counting objects: 100% (191/191), done.
remote: Compressing objects: 100% (159/159), done.
remote: Total 191 (delta 42), reused 133 (delta 17), pack-reused 0
Receiving objects: 100% (191/191), 175.37 KiB | 454.00 KiB/s, done.
Resolving deltas: 100% (42/42), done.
masa@DESKTOP-0CNPS43:~/environment$ ls
RailsTutorial
masa@DESKTOP-0CNPS43:~/environment$ cd RailsTutorial/
masa@DESKTOP-0CNPS43:~/environment/RailsTutorial$ docker-compose build
Traceback (most recent call last):
  File "urllib3/connectionpool.py", line 677, in urlopen
  File "urllib3/connectionpool.py", line 392, in _make_request
  File "http/client.py", line 1252, in request
  File "http/client.py", line 1298, in _send_request
  File "http/client.py", line 1247, in endheaders
  File "http/client.py", line 1026, in _send_output
  File "http/client.py", line 966, in send
  File "docker/transport/unixconn.py", line 43, in connect
PermissionError: [Errno 13] Permission denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "requests/adapters.py", line 449, in send
  File "urllib3/connectionpool.py", line 727, in urlopen
  File "urllib3/util/retry.py", line 403, in increment
  File "urllib3/packages/six.py", line 734, in reraise
  File "urllib3/connectionpool.py", line 677, in urlopen
  File "urllib3/connectionpool.py", line 392, in _make_request
  File "http/client.py", line 1252, in request
  File "http/client.py", line 1298, in _send_request
  File "http/client.py", line 1247, in endheaders
  File "http/client.py", line 1026, in _send_output
  File "http/client.py", line 966, in send
  File "docker/transport/unixconn.py", line 43, in connect
urllib3.exceptions.ProtocolError: ('Connection aborted.', PermissionError(13, 'Permission denied'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "docker/api/client.py", line 205, in _retrieve_server_version
  File "docker/api/daemon.py", line 181, in version
  File "docker/utils/decorators.py", line 46, in inner
  File "docker/api/client.py", line 228, in _get
  File "requests/sessions.py", line 543, in get
  File "requests/sessions.py", line 530, in request
  File "requests/sessions.py", line 643, in send
  File "requests/adapters.py", line 498, in send
requests.exceptions.ConnectionError: ('Connection aborted.', PermissionError(13, 'Permission denied'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bin/docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 67, in main
  File "compose/cli/main.py", line 123, in perform_command
  File "compose/cli/command.py", line 69, in project_from_options
  File "compose/cli/command.py", line 132, in get_project
  File "compose/cli/docker_client.py", line 43, in get_client
  File "compose/cli/docker_client.py", line 170, in docker_client
  File "docker/api/client.py", line 188, in __init__
  File "docker/api/client.py", line 213, in _retrieve_server_version
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', PermissionError(13, 'Permission denied'))
[16232] Failed to execute script docker-compose

どうやら"PermissionError"がでているようだ。
権限の問題であるように見えるので、
"sudo docker-compose build"を実行してみる。

"sudo docker-compose build"を実行してみる。

"sudo docker-compose build"を実行。

masa@DESKTOP-0CNPS43:~/environment/RailsTutorial$ sudo docker-compose build
[sudo] password for masa: 
postgres uses an image, skipping
redis uses an image, skipping
Building web
Step 1/22 : FROM ruby:2.7.2-alpine AS builder
2.7.2-alpine: Pulling from library/ruby
801bfaa63ef2: Pull complete
ba81004cc3f9: Pull complete
...(省略)
Step 22/22 : CMD ["rails", "server", "-b", "0.0.0.0", "-p", "3000"]
 ---> Using cache
 ---> 95c351e8be42

Successfully built 95c351e8be42
Successfully tagged rails-app:0.3.0

ビルド成功キタ━━━━(゚∀゚)━━━━!!
Docker Desktopでも起動することができました。

~fin~

このスクラップは2021/01/07にクローズされました
作成者以外のコメントは許可されていません