Hello. This is Hasegawa. Posted as an article on Yayoi Advent Calendar 2020.
As a personal hobby, I tried using Docker Desktop for Windows on Windows 10 Home at home. This time, I wrote an article about preparations for using Docker Desktop for Windows and impressions of using it.
・ Windows 10 Home Edition ・ 64-bit version (* WSL cannot be used with 32-bit version!)
Originally, I deployed a web application on Google Cloud Platform (GCP) for the purpose of studying technology. At that time, I wanted to use Docker, which is a trend (?) In recent years.
Since Windows 10 on my home PC is a "Home" edition, I can't use Hyper-V. I did a little research on how to use Docker on Windows 10 Home, but I thought that "environment construction seems to be a little troublesome ...", and there was a section that I was a little shy of.
In my lazy ear, "From Windows version 2004, ** WSL2 ** and ** Docker Desktop for Windows ** can be used on Windows 10 Home. You can use it without Hyper-V." Information has jumped in. [^ 1] "I have no choice but to try this!"
Abbreviation for Windows Subsystem for Linux 2. It is a mechanism to run Linux on Windows.
The differences between WSL1 and WSL2 are described in detail in the following Microsoft documentation. https://docs.microsoft.com/ja-jp/windows/wsl/compare-versions
[^ 1]: WSL2 is also available in version 1903/1909 with the cumulative update.
https://forest.watch.impress.co.jp/docs/news/1272017.html
To put it briefly, Docker Desktop for Windows is ready to use after the following preparations.
WSL2 is available from Windows 10 version "2004". [^ 1] I'm lazy, and I've left the update for a long time, so the version remained "1909". When I checked "Settings"-> "Update and Security"-> "Windows Update", I was able to get a new version of Windows, so I updated it without checking it very well. After updating, when I checked the version of Windows, it was "20H2". ** "What? What is H2? Hydrogen ...?" ** After a little research, it was Windows 10 October 2020 Update ... In other words, it is a newer version than "2004". This completes the Windows 10 version upgrade.
I downloaded and installed Docker Desktop for Windows from the following site. https://hub.docker.com/editions/community/docker-ce-desktop-windows
When you launch Docker Desktop for Windows using the previous procedure, the following message will appear ... "By the way, I didn't have WSL2 installed ..." The order was a little messed up, but I downloaded and installed the "WSL2 Linux Kernel Update Package for x64 Machines" from the following site. https://aka.ms/wsl2kernel
Now that you're ready, start Docker Desktop for Windows. The following screen has been launched.
This is the screen where a list of running containers is displayed. This is what it looks like now because no container is running. Click "Images" on the left side of the screen to open the following screen.
A list of Docker images is displayed here. This is what it looks like because there are no images now.
Create the image from the command prompt or Windows PowerShell. For the time being, I wanted to see how it works, so I created the following Dockerfile. Open port 80 and install the Apache and .NET Core SDKs.
FROM centos:7
RUN echo "now building..."
RUN yum -y install httpd
EXPOSE 80
RUN rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
RUN yum -y install dotnet-sdk-3.1
Start a command prompt in the directory where you put the Dockerfile, and execute Docker Build.
cmd.exe
Working directory>docker build -t testmycontainer .
[+] Building 1.8s (9/9) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/centos:7 1.8s
=> [1/5] FROM docker.io/library/centos:7@sha256:0f4ec88e21daf75124b8a9e5ca03c37a5e937e0e108a255d890492430789b60e 0.0s
=> CACHED [2/5] RUN echo "now building..." 0.0s
=> CACHED [3/5] RUN yum -y install httpd 0.0s
=> CACHED [4/5] RUN rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm 0.0s
=> CACHED [5/5] RUN yum -y install dotnet-sdk-3.1 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:6c50ce36ff73cec713b16e6384a8cb7d7ce35db507fb92dee249f77f53396bde 0.0s
=> => naming to docker.io/library/testmycontainer 0.0s
If you check the list of images with Docker Desktop for Windows ...
I was able to confirm that the image was created.
I would like to create a container from the image I created earlier and execute it. When you move the cursor to the line of the image name, the "RUN" button will be displayed. Click it.
Then, the container name and port selection screen will be displayed. Enter it and click "RUN".
Then click "Containers/Apps" on the left side of the screen to check the running containers.
Oh! moving! For the time being, let's check the command with the docker ps command.
cmd.exe
Working directory>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d1eee1f16576 testmycontainer:latest "/bin/bash" 2 minutes ago Up 2 minutes 0.0.0.0:49153->80/tcp Test
It looks like it's working!
From now on, I think it will be very convenient because I can check if the locally developed program works on Docker even on Windows 10 Home and deploy it in a remote production environment (although it is within the scope of personal play).
When I have time, I would like to keep posting articles such as deployment!
Recommended Posts