简体   繁体   English

Windows 无法识别 Docker 命令

[英]Windows doesn't recognize Docker command

I already installed Docker for windows.我已经为 windows 安装了 Docker。 when I type docker --version command in Command prompt, it doesn't recognize it at all.当我在命令提示符下键入docker --version命令时,它根本无法识别它。

The message will be this:消息将是这样的:

'docker' is not recognized as an internal or external command,
operable program or batch file.

docker --version 命令在 cmd

Did I miss something?我错过了什么?

I had installed Docker 18.06.1-ce version on my Windows 10 machine and faced the similar issue, even though the docker was added the Windows %PATH%.我在我的 Windows 10 机器上安装了 Docker 18.06.1-ce 版本并遇到了类似的问题,即使 docker 添加了 Windows %PATH%。

I moved the docker path to the bottom and that solved my problem.我将 docker 路径移到了底部,这解决了我的问题。

在此处输入图像描述

在此处输入图像描述

我重新启动了系统,它工作,也许我们可以说需要重新启动。

You need to start the docker first if you have not and then open powershell .如果还没有,则需要先启动docker,然后再打开powershell

In the powershell, try to run docker commands.在 powershell 中,尝试运行 docker 命令。

I installed docker Docker version 19.03.13 build 4484c46d9d, in Windows 10 pro 1903. I was facing the same issue, then I just renamed 'com.docker.cli' to 'docker' and set the environment variable to 'C:\Program Files\Docker\Docker\resources\bin'我在 Windows 10 pro 1903 中安装了 docker Docker 版本 19.03.13 build 4484c46d9d。我遇到了同样的问题,然后我将 'com.docker.cli' 重命名为 'docker' 并将环境变量设置为 'C:\Program文件\Docker\Docker\resources\bin'

Problem Resolved.问题已解决。

Refer the image:参考图片:

https://drive.google.com/file/d/1sZwx4udOzJeITV2RDGQKlsOt_TF4Wq2N/view?usp=sharing https://drive.google.com/file/d/1sZwx4udOzJeITV2RDGQKlsOt_TF4Wq2N/view?usp=sharing

https://drive.google.com/file/d/1DpW2DR2n_jCGezwrXuhNtXpSTBWmEDJk/view?usp=sharing https://drive.google.com/file/d/1DpW2DR2n_jCGezwrXuhNtXpSTBWmEDJk/view?usp=sharing

将“com.docker.cli”重命名为“docker”帮助我最终让 windows powershell 和 cmd 终端识别 docker 命令。

Add docker to PATH variable & refreshenv to keep using the same command prompt将 docker 添加到PATH变量和refreshenv以继续使用相同的命令提示符


If you've installed using docker toolbox the install path "C:\Program Files\Docker Toolbox"如果您使用 docker toolbox 安装,则安装路径"C:\Program Files\Docker Toolbox"

Manually using Environmental Variable > Path (add docker path here)手动使用环境变量 > 路径(在此处添加 docker 路径)


Using Command Line使用命令行

For temporary use set PATH=%PATH%;C:\Program Files\Docker Toolbox临时使用set PATH=%PATH%;C:\Program Files\Docker Toolbox

  • Make sure to take a back up of PATH by echo %PATH% before doing this确保在执行此操作之前通过echo %PATH%备份PATH

For permanent change setx PATH=%PATH%;C:\Program Files\Docker Toolbox对于永久更改setx PATH=%PATH%;C:\Program Files\Docker Toolbox

docker: command not found

Windows 7: Just set the path of docker in system variable Windows 7:只需在系统变量中设置 docker 的路径

Step:1 [Click on path -> edit-> paste the docker location]步骤:1 [点击路径->编辑->粘贴docker位置]

在此处输入图像描述

Step:2 [Paste the docker location] In my case C:\Program Files\Docker Toolbox .步骤:2 [粘贴 docker 位置]在我的情况下 C:\Program Files\Docker Toolbox

在此处输入图像描述

now check $ docker version现在检查$ docker 版本

Make sure the docker.exe path (C:\Program Files\Docker\Docker\resources\bin) is added to the PATH variable.确保将 docker.exe 路径 (C:\Program Files\Docker\Docker\resources\bin) 添加到 PATH 变量中。

You can check it as follows:您可以按如下方式检查:

ECHO %PATH%

The docker path had to be appended at the end of the PATH in my case.在我的情况下,docker 路径必须附加在 PATH 的末尾。 After that docker cmd was recognized.之后 docker cmd 被识别。

Run as administrator worked for me, both powershell and bash on windows.以管理员身份运行,Windows 上的 powershell 和 bash 都为我工作。 I did not need to restart.我不需要重新启动。

Just Restart the system, it is always good practice to restart the system when you install or uninstall any application.只需重新启动系统,在安装或卸载任何应用程序时重新启动系统始终是一个好习惯。 Hope this works :)希望这有效:)

You need to restart the system after installation.安装后需要重启系统。 It worked for me.它对我有用。

I checked environment variables and noticed that docker path is as the following path in which "R" in resources uppercase.我检查了环境变量并注意到 docker 路径与以下路径一样,其中资源大写的“R”。 I fixed the case and everything worked as expected Path: "C:\Program Files\Docker\Docker\Resources\bin"我修复了这个案例,一切都按预期工作路径:“C:\Program Files\Docker\Docker\Resources\bin”

Try to install GIT bash and then run this command on it for Windows:尝试安装 GIT bash,然后在 Windows 上运行以下命令:

base=https://github.com/docker/machine/releases/download/v0.16.0 &&
mkdir -p "$HOME/bin" &&
curl -L $base/docker-machine-Windows-x86_64.exe > "$HOME/bin/docker-machine.exe" &&
chmod +x "$HOME/bin/docker-machine.exe"

Click Here.点击这里。

there is some issues with PowerShell or new version of docker due to which I was facing the same issue but then I went to this page and got way to run it. PowerShell 或新版本的 docker 存在一些问题,因此我遇到了同样的问题,但后来我去了这个页面并找到了运行它的方法。

PS: GIT bash is required. PS:需要 GIT bash。

如果您在 Windows 中安装了 Docker Toolbox,请添加环境变量。

PATH = "location of folder that contains docker-machine"

I also face a problem with the installation and running docker.我也面临安装和运行 docker 的问题。 I'm not sure you how did you install docker.我不确定你是如何安装 docker 的。 I tried this way.我试过这种方式。 I've downloaded the docker toolbox ( https://github.com/docker/toolbox/releases ) which comes up with docker,docker-machine.我已经下载了 docker,docker-machine 附带的 docker 工具箱( https://github.com/docker/toolbox/releases )。 Oracle Virtual box which is pretty much enough to start docker locally.Please make sure you have git bash installed in your local. Oracle Virtual box 足以在本地启动 docker。请确保您在本地安装了 git bash。 Once the toolbox installation is done click the icon generated on the desktop .工具箱安装完成后,单击桌面上生成的图标。 Make sure this icon target to your Git bash.exe (you can verify this by right click on icon and find target).确保此图标指向您的 Git bash.exe(您可以通过右键单击图标并找到目标来验证这一点)。 and verify docker version并验证 docker 版本

For me, I had to ensure the check box Enable Hyper-V Windows Features is checked as I was installing.对我来说,我必须确保在安装时选中启用 Hyper-V Windows 功能复选框。

I just wanted to have client installed, without the engine.我只是想安装客户端,没有引擎。 So earlier, as I was installing, I unchecked that option.所以早些时候,当我安装时,我取消了该选项。 And after successful installation, I get the error - windows does not recognize docker.成功安装后,我收到错误 - windows 无法识别 docker。

But now that reinstalled with the checkbox checked, things are working fine now.但是现在重新安装并选中复选框,现在一切正常。

启用 Hyper-V Windows 功能

I noticed that running docker commands before startup causes this issue, but ensuring that docker is running and executing the commands after, they are then recognised.我注意到在启动之前运行 docker 命令会导致此问题,但确保 docker 正在运行并在之后执行命令,然后它们会被识别。 在此处输入图像描述

For those who are facing docker issue on VS Code对于那些在 VS Code 上遇到 docker 问题的人

I was trying on VS Code Terminal after installation.安装后我在VS Code终端上尝试。 Restarted and was still facing issue.重新启动,仍然面临问题。

在此处输入图像描述

Then I tried with fresh terminal of Command Prompt -- it worked!然后我尝试使用命令提示符的新终端——它有效!

在此处输入图像描述

After that it also working fine on vs code.之后它在 vs 代码上也可以正常工作。

In VS Code - close all terminals and open fresh terminal and try test command:VS Code中 - 关闭所有终端并打开新终端并尝试测试命令:

docker --version

在此处输入图像描述

I've tried to play with paths but it didn't work.我试过玩路径,但没有用。 Then I found that it works for me only when I type docker-compose instead of docker .然后我发现它只有在我输入docker-compose而不是docker时才对我docker So docker-compose version or docker-compose images worked for me as well, as any other command.所以docker-compose versiondocker-compose images也对我docker-compose images ,就像任何其他命令一样。

不幸的是,经过多次尝试和重新启动,我卸载了 docker 并重新安装了它,我不得不重新构建所有东西。

我遇到了同样的问题,我在 Powershell 中尝试过它们,它可以工作 someHo

  1. Download "docker-machine-Windows-x86_64.exe" from: https://github.com/docker/machine/releases从以下网址下载“docker-machine-Windows-x86_64.exe”: https ://github.com/docker/machine/releases
  2. Rename "docker-machine-Windows-x86_64.exe" to "docker-machine.exe".将“docker-machine-Windows-x86_64.exe”重命名为“docker-machine.exe”。
  3. Copy "docker-machine.exe" to path C:\Program Files\Docker\Docker\resources\bin .将“docker-machine.exe”复制到路径C:\Program Files\Docker\Docker\resources\bin

图片

I facing the same issue when I try to run docker -v in Vscode Terminal after install it.当我在安装后尝试在 Vscode 终端中运行 docker docker -v时遇到了同样的问题。 I try to use cmd and git bash it work fine.我尝试使用 cmd 和 git bash 它工作正常。 Restart your vscode will solve it重启你的vscode就解决了

just add this path in your "Path" inside env variables inside windows只需将此路径添加到 windows 内 env 变量中的“路径”中

C:\Program Files\Docker\Docker\resources\bin C:\Program Files\Docker\Docker\resources\bin

then restart your gitbash or cmd or...然后重新启动您的 gitbash 或 cmd 或...

everything goes well after that !之后一切顺利!

2022 - Windows 11 2022 - Windows 11

Add these paths to the PATH variable.将这些路径添加到 PATH 变量。

C:\Program Files\Docker\Docker\resources\bin

C:\ProgramData\DockerDesktop\version-bin

Docker PATH variable Windows 11 Docker 路径变量 Windows 11

For windows server对于 Windows 服务器

Use Install-windowsFeature Containers使用Install-windowsFeature 容器

就我而言,我切换到 Windows 命令提示符而不是 VScode 终端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM