Comfortable Docker environment created with WSL2 CentOS7 and Docker Desktop

Introduction

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.

Premise

procedure

The general procedure is as follows.

  1. Install CentOS7 on WSL2
  2. Install Docker on CentOS7
  3. Install Docker Desktop on Windows 10
  4. WSL2 integration settings in Docker Desktop

1. Install CentOS7 on WSL2

Obtaining CentOS7

Download CentOS 7.zip from GitHub. https://github.com/wsldl-pg/CentWSL/releases/tag/7.0.1907.3

Installation of CentOS7

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 Windows Terminal

Install from the Windows Store for CentOS7 operation.

Boot from Windows Terminal

When you start Windows Terminal and open a new tab, CentOS7 is added to the list, so click it to confirm that it starts.

Change the startup directory to root's home directory

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.

2. Install Docker on CentOS7

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

3. Install Docker Desktop on Windows 10

See Docker Official.

4. WSL2 integration settings in Docker Desktop

Open the Docker Desktop settings screen and go to Resources-> WSL INTEGRATION. image.png

Turn on the CentOS7 toggle under Enable integration with additional distros. Press the Apply & Restart button.

Operation check

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/

Check with Docker Desktop

"Hello-world" has been added to the list of images, and you can see that it is linked with CentOS. image.png

Confirmed from CentOS7

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.

Reference article

Install CentOS 7 with WSL

Recommended Posts

Comfortable Docker environment created with WSL2 CentOS7 and Docker Desktop
Comfortable development life with WSL2 + Docker Desktop + GPU
Build docker environment with WSL
Build Go development environment with WSL2 + Docker Desktop + VSCode (Remote --Containers)
Lightweight PHP 7.4 development environment created with Docker
[Memo] Create a CentOS 8 environment easily with Docker
Rails development environment created with VSCode and devcontainer
Explode Docker with WSL2
[First team development ③] Share the development environment created with Docker
Build Java development environment with WSL2 Docker VS Code
Build WordPress environment with Docker (Local) and AWS (Production)
Create Chisel development environment with Windows10 + WSL2 + VScode + Docker
Compiled kotlin with cli with docker and created an environment that can be executed with java
Pytorch execution environment with Docker
WSL2 + VSCode + Docker development environment
Docker autostart settings with wsl2
React environment construction with Docker
Easy environment construction of MySQL and Redis with Docker and Alfred
Build a Node-RED environment with Docker to move and understand
Create Rails5 and postgresql environment with Docker and make pgadmin available
Rails + MySQL environment construction with Docker
Create a Vue3 environment with Docker!
Node.js environment construction with Docker Compose
Build Couchbase local environment with Docker
Environment construction with Docker for beginners
Build PlantUML environment with VSCode + Docker
Build environment with vue.js + rails + docker
Hello World with Docker and C
Build Rails environment with Docker Compose
Create SolrCloud verification environment with Docker
WordPress with Docker Compose on CentOS 8
[Introduction] Installation of Docker Desktop for Mac for the first time and setup of virtual environment construction of CentOS
Create Laravel environment with Docker (docker-compose)
Docker Desktop WSL 2 backend Japanese translation
Microservices With Docker and Cloud Performance
Challenge to install WSL2 and docker
Build docker + laravel environment with laradock
I built a rails environment with docker and mysql, but I got stuck
Let's install Docker on Windows 10 and create a verification environment for CentOS 8!
[Copy and paste] Build a Laravel development environment with Docker Compose Part 2
Launching the production environment with docker + rails (ver5.2) and errors that occurred
[Node.js express Docker] How to define Docker environment variables and load them with node.js
Alert slack with alert manager in Docker environment
GPU environment construction with Docker [October 2020 version]
Rails environment construction with Docker (personal apocalypse)
Developed with CentOS8.1 + Emacs26.1 + WSL2 with Ubuntu20.04 + VcXsrv
Laravel development environment construction with Docker (Mac)
Build a PureScript development environment with Docker
Build and manage RStudio environment with Docker-compose
Create Rails 6 + MySQL environment with Docker compose
Install Docker Desktop for Mac with Homebrew
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
Edit Mysql with commands in Docker environment
Create a MySQL environment with Docker from 0-> 1
Build DNS server with CentOS8 and bind
Introducing Docker Desktop for Windows on WSL2
Communicate Gitlab and Gitlab Runner launched with Docker
Laravel + MySQL + phpMyadmin environment construction with Docker
Build a Wordpress development environment with Docker
Image flew when updating Docker with WSL2
GPU recognition with docker using WSL2 (August 2020)