For those who are familiar with Windows, Linux-based CLIs are difficult to get along with. The WSL2 integration feature included in the Windows version of Docker Desktop allows you to manage containers with a Windows GUI, which makes it somewhat easier to handle.
The general procedure is as follows.
Download CentOS 7.zip from GitHub. https://github.com/wsldl-pg/CentWSL/releases/tag/7.0.1907.3
Unzip the downloaded file to the following location. C:\Users\username\AppData\Local\Packages
As a result, the following folder is created and CentOS.exe is output to the folder. C:\Users\username\AppData\Local\Packages\CentOS7
It will be installed when you run the unzipped CentOS7.exe.
Install from the Windows Store for CentOS7 operation.
When you start Windows Terminal and open a new tab, CentOS7 is added to the list, so click it to confirm that it starts.
Since the current directory when starting CentOS7 is the home directory of the user on Windows, it is inconvenient, so open the setting and change it to the home directory of root.
Open setting.json with any editor and add the setting of startingDirectory to the setting part of CentOS7.
setting.json
{
"guid": "{a8202b0e-781a-5dab-98e2-e9d469a63619}",
"hidden": false,
"name": "CentOS7",
"source": "Windows.Terminal.Wsl",
"startingDirectory" : "//wsl$/CentOS7/root"
}
Restart CentOS7 and check that the settings are reflected.
The root password setting is omitted.
From here, operate CentOS7 with CLI. There are only 4 commands, so I'll do my best. For details of each command, refer to Docker official website "Getting Docker CE (for CentOS)".
First, install Software Collections with the following command.
$ yum install -y centos-release-scl-rh
Then install the required packages.
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Add a Docker repository.
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Update the yum package index.
$ sudo yum makecache fast
Then install Docker for CentOS. (If you do not specify the version, Docker will not start, so install the version with "centos")
$ sudo yum install -y docker-ce-18.03.1.ce-1.el7.centos
If you try to start Docker in this state, an error will occur, but don't worry.
#It still doesn't work now
$ sudo systemctl start docker
Failed to get D-Bus connection: Operation not permitted
See Docker Official.
Open the Docker Desktop settings screen and go to Resources-> WSL INTEGRATION.
Turn on the CentOS7 toggle under Enable integration with additional distros. Press the Apply & Restart button.
Execute the following command from CentOS7.
$ docker run hello-world
If the container image of hello-world is pulled, the container starts, and "Hello form Docker!" Is displayed, the operation check is successful.
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
"Hello-world" has been added to the list of images, and you can see that it is linked with CentOS.
Of course, you can see the same thing on CentOS.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd 2.4 dd85cdbb9987 5 weeks ago 138MB
alpine/git latest 94f8849864da 3 months ago 28.4MB
hello-world latest bf756fb1ae65 12 months ago 13.3kB
That's it. Check the container status, run, and access the console from Docker Desktop.
I hope it helps someone somewhere.
Recommended Posts