Windows上でWindowsをDockerでGUIありで動かせないかなといろいろ調べてみましたが、そもそもHyper-Vを使えよ、って意見が大多数だったので、諦めて、Windows Server 2022のwindows subsystem for linuxにOracle LinuxとDockerをインストールして、「dockur/windows」を持ってきて動かす方法を試してみました。
それぞれは単純な手順ですが、勉強を兼ねた備忘録です。
事前準備(ホストOSがLinuxの場合は不要)
wslのインストール
wsl --install
wsl --update
Oracle Linuxのインストール
wsl --list --online
NAME FRIENDLY NAME
Ubuntu Ubuntu
Debian Debian GNU/Linux
kali-linux Kali Linux Rolling
Ubuntu-18.04 Ubuntu 18.04 LTS
Ubuntu-20.04 Ubuntu 20.04 LTS
Ubuntu-22.04 Ubuntu 22.04 LTS
Ubuntu-24.04 Ubuntu 24.04 LTS
OracleLinux_7_9 Oracle Linux 7.9
OracleLinux_8_7 Oracle Linux 8.7
OracleLinux_9_1 Oracle Linux 9.1
openSUSE-Leap-15.5 openSUSE Leap 15.5
SUSE-Linux-Enterprise-Server-15-SP4 SUSE Linux Enterprise Server 15 SP4
SUSE-Linux-Enterprise-15-SP5 SUSE Linux Enterprise 15 SP5
openSUSE-Tumbleweed openSUSE Tumbleweed
wsl --install -d OracleLinux_8_7
ダウンロード中: Oracle Linux 9.1
インストール中: Oracle Linux 9.1
Oracle Linux 9.1 がインストールされました。
Oracle Linux 9.1 を起動しています...
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username:
後は、適当にユーザ名とパスワードを入力します。
OralceLinux上でDockerをインストール
パッケージの削除
sudo dnf remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
dnf-utilのインストール
sudo dnf install dnf-utils
Dockerのレポジトリを追加
sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
dnf repolist
repo id repo name
docker-ce-stable Docker CE Stable - x86_64
ol8_UEKR6 Latest Unbreakable Enterprise Kernel Release 6 for Oracle Linux 8 (x86_64)
ol8_appstream Oracle Linux 8 Application Stream (x86_64)
ol8_baseos_latest Oracle Linux 8 BaseOS Latest (x86_64)
Dockerのインストール
パッケージ追加
sudo dnf install docker-ce docker-ce-cli containerd.io
サービスの起動と自動起動
sudo systemctl start docker
sudo systemctl status docker
sudo systemctl enable docker
Docker-Composeのインストール
レポジトリをダウンロードと実行権限付与
※何故か最新版にLinux-x86_64のバイナリーがないので、2.28.0をダウンロードしました。
sudo curl -L "https://github.com/docker/compose/releases/download/v2.28.0/docker-compose-linux-x86_64" -o ./docker-compose
sudo chmod +x /usr/local/bin/docker-composesudo chmod +x /usr/local/bin/docker-compose
initからsystemdへの変更
OracleLinux上で、「/etc/wsl.conf」を以下のように作成。これをしないと、Dockerデーモンが動きませんでした。
[boot]
systemd=true
compose.yamlの作成
以下のような
構成ファイルを作成しました。
services:
windows:
image: dockurr/windows
container_name: windows
environment:
VERSION: "2016"
LANGUAGE: "Japanese"
REGION: "ja-JP"
KEYBOARD: "ja-JP"
RAM_SIZE: "8G"
CPU_CORES: "6"
DISK_SIZE: "100G"
cap_add:
- NET_ADMIN
ports:
- 8006:8006
- 3389:3389/tcp
- 3389:3389/udp
stop_grace_period: 2m
volumes:
- ./data:/storage
対象OSはWindows Server 2016、日本語でデータをdataフォルダに保存することとします。
Dockerから起動
OSインストール
構成ファイルをおいたフォルダで、以下のようなコマンドを実行
docker compose up -d
[+] Running 7/7
✔ windows Pulled 8.3s
✔ 28b9a042b2f1 Pull complete 4.5s
✔ 607a8c080628 Pull complete 5.1s
✔ 7da360374e0b Pull complete 5.1s
✔ 75e784666a3f Pull complete 5.2s
✔ 45217bed6de1 Pull complete 5.2s
✔ e0d2bf59cee9 Pull complete 5.3s
[+] Running 1/1
✔ Container windows Started
OSイメージのダウンロードからOSのインストール、起動
ブラウザで、「localhost:8006」へアクセスすると、QEMU経由でのインストール状況を見ることが出来ます。
まず初めにWindows Server 2016のOSイメージをダウンロードしています。
気になった点
仮想化のネスト構造(on QEMU of Docker of WSL) WSL上のLinuxでDockerを動かして、Windowsを動かしているので、あまり効率の良いシステムではない。 本来はLinux上動かしたほうがいい??
Windowsライセンス どうやら、非アクティベーション状態でのインストールであるため、継続利用するためには正規ライセンスが別途必要となるようです。
ネットワーク 厳密にはDockerでWindowsが動くわけではなく、インストールISOをダウンロードしてきて、QEMUやKVMなどの仮想化ツールを使ってWindowsを動かしているようです。そのため、ネットワーク構成が通常のDockerネットワーク内にWindowsOSがいるわけではない。以下は”Windowsコンテナ”に対して、”ifconfig”を打った結果です。
docker exec -it windows "ifconfig"
dockerbridge: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 20.20.20.1 netmask 255.255.255.0 broadcast 20.20.20.255
inet6 fe80::384c:beff:fefe:4908 prefixlen 64 scopeid 0x20<link>
ether 02:42:75:33:a1:76 txqueuelen 1000 (Ethernet)
RX packets 375 bytes 142219 (138.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 249 bytes 133304 (130.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.0.2 netmask 255.255.0.0 broadcast 172.18.255.255
ether 02:42:ac:12:00:02 txqueuelen 0 (Ethernet)
RX packets 1851 bytes 235486 (229.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2965 bytes 2660572 (2.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 4058 bytes 2613646 (2.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4058 bytes 2613646 (2.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
qemu: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST> mtu 1500
inet6 fe80::42:75ff:fe33:a176 prefixlen 64 scopeid 0x20<link>
ether 02:42:75:33:a1:76 txqueuelen 1000 (Ethernet)
RX packets 375 bytes 147469 (144.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 260 bytes 134130 (130.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
どんなメリットがあるの? MacやLinuxを使っている人から見ると、簡易にコマンド一つでOSのインストールまでが完了するので、簡易な検証環境を作りやすい。
Comments