In Windows 10 Pro, Hyper-V is installed by default, so you can easily build an environment using Docker desktop for windows, but in Windows 10 Home that does not have Hyper-V, building docker is a little troublesome.
Therefore, there are several ways to use docker under Windows 10 Home environment.
This time, we will set up the first method using WSL, which has a fast initial execution speed and few steps to build a development environment.
** Install WSL2. ** ** Install WSL2 so that you can access OS such as ubuntu from Windows OS. The installation procedure of WSL2 is omitted here, but ** WSL2 ** is installed instead of WSL1.
** Install Docker desktop for Windows ** Install Dokcer desktop for Windows (https://docs.docker.com/docker-for-windows/install/) on your Windows machine
** Install docker, docker-compose ** Install the latest version of docker and docker-compose on ubuntu of WSL2. Reference: https://qiita.com/tettsu__/items/85c96850d187e4386c24
For some reason, in Docker desktop for Windows using WSL2, it is not possible to operate the allocation of CPU etc. from the setting screen, so Change the CPU / memory / SWAP / disk size from the terminal.
What we do is make the docker daemon on WSL2 available on Docker desktop for Windows.
On the settings screen> General,ʻUse the WSL2 based engine` ✔
Go to Settings> Resources> WSL INTEGRATIONʻEnable integration with my default WSL distro`.
If ubuntu is installed on WSL2 and set correctly, a message like "Ubuntu" will appear as shown in the above picture, so turn it on.
** [Note] ** If you cannot check the ✔ column above,
--tcp: // localhost: 2375 cannot be set. (Forgot to export the localhost path to bashrc) --You are using WSL1 instead of WSL2
Such causes are possible. (Please google for details)
Create a project in ubuntu terminal (hereinafter referred to as ubuntu terminal) on WSL2.
ubuntu:~ $ mkdir work
ubuntu:~ $ cd work
ubuntu:~/work $ git clone [email protected]/~
** [Points to note] **
--Generally, you can access the Windows directory from the ubuntu terminal using / mnt / c
,
This time, create a project in the Windows directory, and instead of referencing it from the ubuntu terminal, ** create the project directly in the directory on ubuntu. ** **
(When docker is launched in a project on a Windows directory, it takes a tremendous amount of time to access the disk, and it takes about 5 minutes from launching docker to displaying the initial screen. I stumbled here.)
Open ubuntu terminal and launch docker container.
$ docker-compose up -d
With this, it is ok if you start the container without throwing an error, It wasn't that easy in my environment, so here are the errors I faced and their solutions.
error
ERROR: for rails_1 Cannot start service rails: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"bin/start_dev_server.sh\": stat bin/start_dev_server.sh: no such file or directory": unknown
** Occurrence procedure **
/ mnt / c
docker-compose up
** Cause **
In this case, the root of the absolute path of WSL2 is / mnt / c
,
This was because the Docker for Windows VM applied the root of the absolute path of / C
.
solution Create a project under the Windows directory, stop referencing it, and create a project under the ubuntu directory.
** Reference link **
error
Aws::S3::Errors::RequestTimeTooSkewed: The difference between the request time and the current time is too large.
** Occurrence procedure **
docker-compose up
** Cause ** The cause was that the time of the Docker container running on WSL2 (ubuntu terminal) was significantly different.
Windows host side (correct)
$ data
Sun Aug 30 18:16:29 JST 2020
ubuntu terminal side
$ data
Sun Aug 28 11:16:29 JST 2020
solution
docker-compose.yml
services:
web:
environment:
TZ: Asia/Tokyo
docker-compose.yml
services:
web:
privileged: true
data
command to change the date$ data --set "2020-08-30 18:16:29" //Manually set to the current time
** Memo **
Besides, it seems that you can change the time by using hwclock -s
, but you will die with the following error.
$ hwclock -s
hwclock: Cannot access the Hardware Clock via any known method.
** Reference link **
error
$ docker-compose up
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
** Occurrence procedure **
docker-compose up
** Cause ** The cause I understand is
Another VM is running The virtual machine platform used when using docker, which runs on the Hyper-V platform (which is different from <-Hyper-V) (although this is very annoying), and other virtual machines such as Oracle Virual Box. It seems that using them at the same time is not good because it causes a conflict of Hyper-V platform (?). --Reference link: https://qiita.com/matarillo/items/ca1eecf8f9a3cd76f9ce
WSL is not enabled
I think there are many other causes as well.
solution For cause 1 --Stop other VMs
For cause 2
--Open PowerShell and
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
Reference link: https://qiita.com/aki4000/items/c26e3076c8cec9677415
--Opt 1 [WSL2]: When launching docker of the project under ubuntu directory using WSL2 introduced this time
/mnt/c
project]:
As mentioned above, when using WSL2 to launch docker for a project under a Windows directory--Opt 3 [Vagrant]: When docker is launched on the VM using Vagrant
** Time from accessing localhost to displaying the top page after launching the docker container ⇓ **
Opt 1[WSL2] | Opt 2[WSL2 in /mnt/c project] |
Opt 3[Vagrant] |
---|---|---|
15 s | 5 min | 3 min |
For projects under Windows Dire, you can usually open RubyMine or VS code and edit it, Viewing ubuntu dire from a Windows terminal is a bit tedious, and editing a project under ubuntu dire using an IDE is a bit confusing.
Recommended Posts