今回はWSL2に対応したDocker Desktopを使ってみます。
WSLでDockerを動かしてCentOSのコンテナ環境を作ろうと思います。
WSL上にすでにCentOSいるのにね。
#準備
Docker Desktop for Windowsは Windowsネイティブの Hyper-V 仮想化とネットワークを使用していました。
そのためWindows 10 Professional が前提でした。
今回はWSL2上でDocker Desktopを実行します。
準備としてWSL2を準備しておく必要がありますが、前回まで済ませているのでそちらを参照ください。
PCのOSはWindows HomeでOKです。
WSLを2に更新する
#インストール
Docker Desktop for Windows
こちらからインストールください。
#Dockerの確認
PS C:\Users\XXX> docker version #Dockerのバージョン確認
Client: Docker Engine - Community
Version: 19.03.8
API version: 1.40
Go version: go1.12.17
Git commit: afacb8b
OS/Arch: windows/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.8
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Built: Wed Mar 11 01:29:16 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
PS C:\Users\XXX> wsl -l -v #wsl上にいることを確認
NAME STATE VERSION
* CentOS7 Running 2
Legacy Stopped 1
kali-linux Stopped 1
docker-desktop-data Running 2
Ubuntu Stopped 2
CentOS8 Stopped 2
PS C:\Users\XXX> docker run hello-world #hollow worldの起動確認
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:6a65f928fb91fcfbc963f7aa6d57c8eeb426ad9a20c7ee045538ef34847f44f1
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/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Dockerのインストールは無事できていそうです。
ProだったらHyper-Vは動いてないよね?WSLで動いてるよね?って確認も必要かもしれないけど、HomeのOSなのでそこはなしで!
#CentOSの環境を作ってみる
WSL上にいるCentOSとは別にDockerに仮想環境を作ってみます。
PS C:\Users\XXX> docker pull centos:centos7 #CentOS7 の Docker イメージを取得
centos7: Pulling from library/centos
524b0c1e57f8: Pull complete
Digest: sha256:e9ce0b76f29f942502facd849f3e468232492b259b9d9f076f71b392293f1582
Status: Downloaded newer image for centos:centos7
PS C:\Users\XXX> docker image #Docker イメージを確認
centos centos7 b5b4d78bc90c 2 weeks ago 203MB
hello-world latest bf756fb1ae65 4 months ago 13.3kB
PS C:\Users\XXX> docker run -it --name="centos7f" centos:centos7 /bin/bash #コンテナ を作成・起動
[root@6fbe3d9ddbe5 /]# pwd
/
[root@6fbe3d9ddbe5 /]# exit #コンテナから出ていく
exit
PS C:\Users\XXX> docker ps #動いているコンテナリストを取得(なにもない)
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
PS C:\Users\XXX> docker ps -a #存在するコンテナリストを取得
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6fbe3d9ddbe5 centos:centos7 "/bin/bash" About a minute ago Exited (0) About a minute ago centos7f
5484f528bb46 hello-world "/hello" 24 minutes ago Exited (0) 24 minutes ago festive_ganguly
PS C:\Users\XXX> docker start centos7f #CentOSコンテナを再開
centos7f
PS C:\Users\XXX> docker ps #起動の確認
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6fbe3d9ddbe5 centos:centos7 "/bin/bash" 2 hours ago Up 2 hours centos7f
PS C:\Users\XXX> docker attach centos7f #起動したコンテナに接続
#接続したコンテナでの作業
とりあえずCentOSをアップデートだけしてみます。
[root@6fbe3d9ddbe5 /]# yum update
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: ftp.yz.yamagata-u.ac.jp
* extras: ftp.yz.yamagata-u.ac.jp
* updates: ftp.yz.yamagata-u.ac.jp
base | 3.
extras | 2.
updates | 2.
(1/4): base/7/x86_64/group_gz | 15
(2/4): extras/7/x86_64/primary_db | 19
(3/4): updates/7/x86_64/primary_db | 1.
(4/4): base/7/x86_64/primary_db | 6.
Resolving Dependencies
--> Running transaction check
---> Package bind-license.noarch 32:9.11.4-16.P2.el7_8.2 will be updated
---> Package bind-license.noarch 32:9.11.4-16.P2.el7_8.3 will be an update
---> Package binutils.x86_64 0:2.27-43.base.el7 will be updated
---> Package binutils.x86_64 0:2.27-43.base.el7_8.1 will be an update
---> Package device-mapper.x86_64 7:1.02.164-7.el7_8.1 will be updated
---> Package device-mapper.x86_64 7:1.02.164-7.el7_8.2 will be an update
---> Package device-mapper-libs.x86_64 7:1.02.164-7.el7_8.1 will be updated
---> Package device-mapper-libs.x86_64 7:1.02.164-7.el7_8.2 will be an update
---> Package systemd.x86_64 0:219-73.el7_8.5 will be updated
---> Package systemd.x86_64 0:219-73.el7_8.6 will be an update
---> Package systemd-libs.x86_64 0:219-73.el7_8.5 will be updated
---> Package systemd-libs.x86_64 0:219-73.el7_8.6 will be an update
---> Package yum-plugin-fastestmirror.noarch 0:1.1.31-53.el7 will be updated
---> Package yum-plugin-fastestmirror.noarch 0:1.1.31-54.el7_8 will be an update
---> Package yum-plugin-ovl.noarch 0:1.1.31-53.el7 will be updated
---> Package yum-plugin-ovl.noarch 0:1.1.31-54.el7_8 will be an update
---> Package yum-utils.noarch 0:1.1.31-53.el7 will be updated
---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================== Package Arch Version Repository
===============================================================================================================================================Updating:
bind-license noarch 32:9.11.4-16.P2.el7_8.3 updates
binutils x86_64 2.27-43.base.el7_8.1 updates
device-mapper x86_64 7:1.02.164-7.el7_8.2 updates
device-mapper-libs x86_64 7:1.02.164-7.el7_8.2 updates
systemd x86_64 219-73.el7_8.6 updates
systemd-libs x86_64 219-73.el7_8.6 updates
yum-plugin-fastestmirror noarch 1.1.31-54.el7_8 updates
yum-plugin-ovl noarch 1.1.31-54.el7_8 updates
yum-utils noarch 1.1.31-54.el7_8 updates
Transaction Summary
===============================================================================================================================================Upgrade 9 Packages
Total download size: 12 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
warning: /var/cache/yum/x86_64/7/updates/packages/bind-license-9.11.4-16.P2.el7_8.3.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5
Public key for bind-license-9.11.4-16.P2.el7_8.3.noarch.rpm is not installed
(1/9): bind-license-9.11.4-16.P2.el7_8.3.noarch.rpm | 8
(2/9): device-mapper-libs-1.02.164-7.el7_8.2.x86_64.rpm | 32
(3/9): device-mapper-1.02.164-7.el7_8.2.x86_64.rpm | 29
(4/9): yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm | 3
(5/9): yum-plugin-ovl-1.1.31-54.el7_8.noarch.rpm | 2
(6/9): yum-utils-1.1.31-54.el7_8.noarch.rpm | 12
(7/9): systemd-libs-219-73.el7_8.6.x86_64.rpm | 41
(8/9): systemd-219-73.el7_8.6.x86_64.rpm | 5.
(9/9): binutils-2.27-43.base.el7_8.1.x86_64.rpm | 5.
2/18
Failed to get D-Bus connection: Operation not permitted
Updating : 7:device-mapper-libs-1.02.164-7.el7_8.2.x86_64 3/18
Updating : 7:device-mapper-1.02.164-7.el7_8.2.x86_64 4/18
Updating : yum-utils-1.1.31-54.el7_8.noarch 5/18
Updating : yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch 6/18
Updating : 32:bind-license-9.11.4-16.P2.el7_8.3.noarch 7/18
Updating : binutils-2.27-43.base.el7_8.1.x86_64 8/18
install-info: No such file or directory for /usr/share/info/as.info.gz
install-info: No such file or directory for /usr/share/info/binutils.info.gz
install-info: No such file or directory for /usr/share/info/gprof.info.gz
install-info: No such file or directory for /usr/share/info/ld.info.gz
install-info: No such file or directory for /usr/share/info/standards.info.gz
Updating : yum-plugin-ovl-1.1.31-54.el7_8.noarch 9/18
Cleanup : yum-utils-1.1.31-53.el7.noarch 10/18
Cleanup : yum-plugin-fastestmirror-1.1.31-53.el7.noarch 11/18
Cleanup : 32:bind-license-9.11.4-16.P2.el7_8.2.noarch 12/18
Cleanup : yum-plugin-ovl-1.1.31-53.el7.noarch 13/18
Cleanup : 7:device-mapper-libs-1.02.164-7.el7_8.1.x86_64 14/18
Cleanup : 7:device-mapper-1.02.164-7.el7_8.1.x86_64 15/18
Cleanup : systemd-219-73.el7_8.5.x86_64 16/18
Cleanup : systemd-libs-219-73.el7_8.5.x86_64 17/18
Cleanup : binutils-2.27-43.base.el7.x86_64 18/18
Verifying : 7:device-mapper-1.02.164-7.el7_8.2.x86_64 1/18
Verifying : systemd-219-73.el7_8.6.x86_64 2/18
Verifying : yum-plugin-ovl-1.1.31-54.el7_8.noarch 3/18
Verifying : systemd-libs-219-73.el7_8.6.x86_64 4/18
Verifying : binutils-2.27-43.base.el7_8.1.x86_64 5/18
Verifying : 32:bind-license-9.11.4-16.P2.el7_8.3.noarch 6/18
Verifying : 7:device-mapper-libs-1.02.164-7.el7_8.2.x86_64 7/18
Verifying : yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch 8/18
Verifying : yum-utils-1.1.31-54.el7_8.noarch 9/18
Verifying : systemd-219-73.el7_8.5.x86_64 10/18
Verifying : yum-utils-1.1.31-53.el7.noarch 11/18
Verifying : 32:bind-license-9.11.4-16.P2.el7_8.2.noarch 12/18
Verifying : yum-plugin-ovl-1.1.31-53.el7.noarch 13/18
Verifying : binutils-2.27-43.base.el7.x86_64 14/18
Verifying : 7:device-mapper-libs-1.02.164-7.el7_8.1.x86_64 15/18
Verifying : systemd-libs-219-73.el7_8.5.x86_64 16/18
Verifying : yum-plugin-fastestmirror-1.1.31-53.el7.noarch 17/18
Verifying : 7:device-mapper-1.02.164-7.el7_8.1.x86_64 18/18
Updated:
bind-license.noarch 32:9.11.4-16.P2.el7_8.3 binutils.x86_64 0:2.27-43.base.el7_8.1 device-mapper.x86_64 7:1.02.164-7.el7_8.2 device-mapper-libs.x86_64 7:1.02.164-7.el7_8.2 systemd.x86_64 0:219-73.el7_8.6 systemd-libs.x86_64 0:219-73.el7_8.6
yum-plugin-fastestmirror.noarch 0:1.1.31-54.el7_8 yum-plugin-ovl.noarch 0:1.1.31-54.el7_8 yum-utils.noarch 0:1.1.31-54.el7_8
Complete!
無事できました。
とりあえずアップデートできたのでネットワークにもつながってるぽいしOKです!
#最後に
正直、DockerもよくわかってないのにWSLにCentOS環境作ってWSLのDockerにCentOS作って・・・
自分で何がしたいのかわからないですw
いつも仮想環境作ったりするとネットワークに繋がらなかったり問題が起こりますが今回はセーフ
※前回作ったCentOS8は動いてないので7使ってます。
ちょっといろいろ復習します!!