We suggest how to double-click a batch file and mount the location of the batch file as a WSL2 volume when booting with Docker for Windows.
--People who have installed WSL2 version docker --People who were warned of poor performance when mounting volume when docker started --People who have trouble starting wsl every time they start docker
The following is an example of starting a container image with a batch file name. If you change the batch file name, the container image to be started will change.
buildpack-deps.bat
@setlocal
@set "WORK=/root/workspace"
@cd /d "%~dp0"
@set "IMG=%~n0"
@if "%~0" == "%~f0" set "pause_if_error=@if errorlevel 1 pause"
@for %%i in ( "%CD%" ) do @set "WSL2CD=%%~di"
@for %%i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do @call set "WSL2CD=%%WSL2CD:%%~i=%%~i%%"
@for %%i in ( "%CD%" ) do @call set "WSL2CD=%%WSL2CD:~0,-1%%%%~pnxi"
@set "WSL2CD=/mnt/%WSL2CD:\=/%"
wsl -e docker run -it --rm -w "%WORK%" -v "%WSL2CD%:%WORK%" %IMG% %*
%pause_if_error%
@exit /b %errorlevel%
The mount point is written directly in @ set" WORK = / root / workspace "
, so rewrite it as appropriate.
To fix the image, rewrite @set" IMG =% ~ n0 "
.
Since distro of wsl is not specified, if you want to specify it, add the option of wsl appropriately.
Windows10 1909 Docker version 19.03.13, build 4484c46d9d
When starting docker, go through the wsl command.
The volume specifies the path on wsl.
What is doing the operation of WSL2CD
is the process of converting the windows path to the WSL path.
With this, the warning disappears and it is refreshing!
-Command Prompt (cmd.exe) Private Note
Recommended Posts