Docker ошибка wsl2

При переходе во взрослую разработку рано или поздно мы сталкиваемся с лучшими практиками, со стандартами отрасли и таким образом узнаем о docker и хотим его использовать.

У меня компьютер на windows, действуем по привычной схеме, заходим на официальный сайт docker.com скачиваем дистрибутив, устанавливаем и… ничего не работает!!!

windows 10 wsl 2 installation is incomplete

wsl 2 installation is incomplete

Первое что я увидел при запуске докера “wsl2 installation is incomplete” к счастью microsoft знают что с этим делать и даже дают подробную инструкцию.

Инструкция по установке WSL2 на Windows 10

Запускаем PowerShell с правами админа и включаем компонент “Подсистема Windows для Linux”

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

После этого включаем необязательный компонент “Платформа виртуальных машин”

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Перезагружаем компьютер

Скачиваем и устанавливаем пакет обновления ядра linux

После этого необходимо поставить WSL 2 версией по умолчанию, для этого запускаем PowerShell и выполняем команду

wsl --set-default-version 2

Пробуем снова запустить Docker

Докер в windows 10

Ура все работает! Можем создавать контейнеры!

Thanks @StefanScherer — that worked perfectly. For reference, docker-desktop was stuck in an Installing state.

C:Usersroark>wsl -l -v
  NAME              STATE           VERSION
  docker-desktop    Installing      2

It oddly couldn’t find it when unregistering, but, worked successfully, in any case.

C:Usersroark>wsl --unregister docker-desktop
Unregistering...
The system cannot find the path specified.

C:Usersroark>wsl -l -v
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore

Docker was then successfully able to start with both docker-desktop entries showing in Running state.

C:Usersroark>wsl -l -v
  NAME                   STATE           VERSION
* docker-desktop         Running         2
  docker-desktop-data    Running         2

There’s two ways you can get it to work

  1. Using WSL 2 based engine.
  2. Without using WSL 2 based engine.

1 — Using WSL 2 based engine

In this page under «Download the Linux kernel update package».

Update Linux kernal package

and then Docker will start just fine

Docker running


2 — Without using WSL 2 based engine

If the goal is just to get Docker running, one can simply start by unchecking the box that says «Use the WSL 2 based engine». This can give the following error

Required Windows feature(s) not enabled: Hyper-V.

Required Windows feature(s) not enabled: Hyper-V.

Switch to WSL 2 based engine?

To enable Hyper-V:
https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v

So, in PowerShell 7 run the command

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V
-All

Hyper-V in Windows 10

which requires to Restart the computer to complete the operation. Then, once starting Docker again, you can get the following error

Docker failed to initialize

Docker failed to initialize

One or more errors occurred.

Eventually, just by clicking to start again, Docker will start running

Docker running

docker version

I know this may be outdated for the present question, but this should save us precious time, especially when Windows 20H1=2004 is going to Production this month (May 2020).

  Operating System Version: Windows 10 Education (Same as Enterprise and a superset of Pro).
  Version: 2004
  Build (Version OS): 19041.264
  Others: Windows Feature Experience Pack 120.2202.130.0.
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Shell: WSL Terminal

First, I have installed WSL v1 previously, then executed the procedure to upgrade to WSLv2, and this error shows up: «ERROR: Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?».

Second, to fix that error, I followed instructions stated here: Link, and it worked.

Third, after some tests I think the missing change in the upgrade, was removing the DOCKER_HOST variable from shell’s start script.

SUMMARY: In my case, the procedure for a permanent fix should be the following STEPs:

1. Test if it’s your case unsetting DOCKER_HOST variable (See image below).

2. If the error disappears with previous step, then time to fix changes by removing the setting of the DOCKER_HOST variable in the shell’s start script (In my case was *$HOME/.bashrc*).
  Commented this out:
  #export DOCKER_HOST=tcp://localhost:2375
  #export DOCKER_BUILDKIT=1

  

NOTE: Also include DOCKER_BUILDKIT.

3. Close and open the Terminal.

  Test in Step 1:
enter image description here

Good luck!!

I like this blog. It took me just 1 article to drop all the attention I was paying for the SEO rules.

But let’s move on and try to understand this incompatibility between WSL2 and Docker.

Scenario

You might have been using virtualizations like Hyper-V, VMWare & Co (…no, not you VirtualBox) for a decent number of years now and suddenly Docker comes out and “…PUF…” , it’s such a game changer that you want to keep up with the technology shift.

If you like technology there is the chance that you have already installed Windows Subsystem for Linux and if you are an early adopter like myself you have probably left WSL1 for WSL2 because it’s definitely faster and your terminal doesn’t get stuck when using apt-get

And here comes the trouble: after the first installation everything looks smoothly and Docker is up and running. Then you go to bed because once again is midnight and they after when you wake up and fire up Docker this is what you get:

System.InvalidOperationException: Failed to deploy distro docker-desktop

System.InvalidOperationException: Failed to deploy distro docker-desktop to C:UsersfrancAppDataLocalDockerwsldistro: exit code: -1
 stdout: The system cannot find the file specified.


 stderr: 
   at Docker.ApiServices.WSL2.WslShortLivedCommandResult.LogAndThrowIfUnexpectedExitCode(String prefix, ILogger log, Int32 expectedExitCode) in C:workspacesPR-15138srcgithub.comdockerpinatawinsrcDocker.ApiServicesWSL2WslCommand.cs:line 146
   at Docker.Engines.WSL2.WSL2Provisioning.<DeployDistroAsync>d__17.MoveNext() in C:workspacesPR-15138srcgithub.comdockerpinatawinsrcDocker.DesktopEnginesWSL2WSL2Provisioning.cs:line 169
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Docker.Engines.WSL2.WSL2Provisioning.<ProvisionAsync>d__8.MoveNext() in C:workspacesPR-15138srcgithub.comdockerpinatawinsrcDocker.DesktopEnginesWSL2WSL2Provisioning.cs:line 78
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Docker.Engines.WSL2.LinuxWSL2Engine.<DoStartAsync>d__25.MoveNext() in C:workspacesPR-15138srcgithub.comdockerpinatawinsrcDocker.DesktopEnginesWSL2LinuxWSL2Engine.cs:line 99
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Docker.ApiServices.StateMachines.TaskExtensions.<WrapAsyncInCancellationException>d__0.MoveNext() in C:workspacesPR-15138srcgithub.comdockerpinatawinsrcDocker.ApiServicesStateMachinesTaskExtensions.cs:line 29
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Docker.ApiServices.StateMachines.StartTransition.<DoRunAsync>d__5.MoveNext() in C:workspacesPR-15138srcgithub.comdockerpinatawinsrcDocker.ApiServicesStateMachinesStartTransition.cs:line 67
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Docker.ApiServices.StateMachines.StartTransition.<DoRunAsync>d__5.MoveNext() in C:workspacesPR-15138srcgithub.comdockerpinatawinsrcDocker.ApiServicesStateMachinesStartTransition.cs:line 92

You try to reboot the machine, reboot Docker, nothing works.

Ironically also your Linux bash doesn’t work.

Solution

The root cause is that Docker uses WSL2 and it has overwritten your previous WSL2 installation.

In fact if you run wsl -l -v you will see that both uses WSL2:

wsl -l -v docker

Is sad but in order to fix this issue I had to

  1. remove all my WSL2 flavours this way:
    Uninstall WSL2
  2. Then uninstall Docker
  3. Go to Control Panel > Programs > Programs and Features and disable Windows Subsystem for Linux
  4. Then reboot the machine to finalize everything.
  5. Log back in, enable once again Windows Subsystem for Linux and reinstall all my WSL2 flavours
  6. Now install Docker again but this time at this step untick “Install required Windows components for WSL 2”

Windows components for WSL2

..I know this is not a good news but this is how I fixed it.

Downgrading WSL2 to WSL1 won’t help.

Step 1. Make sure you have installed Docker desktop and WSL 2

Step 2. Open up PowerShell and run the command below to list WSL available:

wsl --list --verbose

You should get something like the following screenshot:

Step 3. Run the following command to set Ubuntu-20.04 version 2 as default:

 wsl --set-default Ubuntu-20.04 2

If you list the WSLs available again you should see the following:

Step 4. Open up Docker Desktop, go to Settings->Resources->WSL Integration. You should then check the Ubuntu 20.04 checkbox.

That’s it! Once you click on “Apply & Restart” you should be able to run docker commands in your Ubuntu 20.04 shells!

Hope that this has helped 🙂

Im trying to start docker in the brand new WSL2 with the following command :

sudo service docker start

then:

sudo service docker status

result :
* Docker is running

BUT on running the test container with :

sudo docker run hello-world

Error:docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

and the status now is
* Docker is not running

….
HERE’s an example im trying to
emulate

MY ENVIRONMENT :

WINDOWS : WINDOWS 10 HOME,
VERSION : 1903,
OS build : 18362.239

DOCKER :
Docker version 18.09.7, build 2d0083d

i HAVE downloaded docker for ubuntu according to the :official website

In windows features i have WSL, Windows Hypervisor Platform, Virtual Machine Platform enabled here’s a screenshot

screenshot

I dont have Hyper-V

I have been using WSL for general purpose proggraming for about 6 months now. Never got stuck this way

How can I run docker natively as promised by the latest WSL2??

Here’s another screenshot

terminal

Recently while setting up docker for Hyperledger in WSL2, I got the following error:

====> hyperledger/fabric-peer:2.3.2
Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?

After a quick research, it turns out that if you are upgrading from WSL1 to WSL2, Windows leaves behind a few legacy settings from WSL1 that causes this issue.

Here is the fix that worked for me:

Step 1: Check if you have the same issue §

  1. In WSL2 terminal, run the command: docker info | head -15
  2. You should see the following error: ERROR: Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?

Step 2: Check if the fix works for you §

  1. Run the command: unset DOCKER_HOST
  2. Follow the previous step again. The error should be gone now.

Step 3: Make the fix permanent §

  1. Edit the .bashrc script with: vi ~/.bashrc
  2. Search for the line with DOCKER_HOST and comment it out like this:
    # export DOCKER_HOST=tcp://localhost:2375
  3. Save the file and reload the terminal settings with: source ~/.bashrc

Понравилась статья? Поделить с друзьями:
  • Docash golf ошибка е02
  • Donationalerts ошибка выплаты на карту
  • Docash golf ошибка u 04
  • Donationalerts ошибка авторизации
  • Docash golf ошибка e11