いろいろやってみるにっき

てきとーに生きている奴の日記

古いエントリのサムネイル画像がリンク切れになってたりするけど、チマチマ修正中


WSLで同じディストリビューションを増殖させる→Docker動かなかったので動かした

同じディストリビューションでも複数持てるようになった。でもDockerが動かない。

 

shigeo-t.hatenablog.com

 

Docker動かず

手順とエラーメッセージを再現するためにもう一個Ubuntu18.04を作った。Dockerを起動しようとするとこんなエラーが出る。

shigeo@EAGLEII:~$ sudo systemctl start docker
System has not been booted with systemd as init system (PID 1). Can't operate.

 

どうやらsystemdが動かないらしい。

shikiyura.com

調べてみると、Linuxが起動するときすべてのプロセスの最初として「systemd」が起動し、すべてのプロセスの親としてふるまうようです。

(中略)

実際にWSL2上でプロセスを確認してみると、PID 1が「/init」となっていて「systemd」ではありません。
これが原因でsystemctlが動いていないようです。
エラーメッセージから考えても、PID 1がsystemdになればよい、ということです。

 

PID 1をsystemdにする

上記ブログでは下記をインストールしている。ただ、コマンドをコピペしてもうまくいかない。

  • dotnet-runtime-3.1
  • daemonize
  • genie

dotnet-runtime-3.1とdaemonizeのインストール

コピペで実行するとこのようにエラーになる。

sudo apt install git dotnet-runtime-3.1 daemonize
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
E: パッケージ dotnet-runtime-3.1 が見つかりません
E: 'dotnet-runtime-3.1' に一致するパッケージは見つかりませんでした
E: 正規表現 'dotnet-runtime-3.1' ではパッケージは見つかりませんでした

先に書かれているdotnet-runtime-3.1がエラーなのでdaemonizeはインストールされていない。

そこでまずdaemonizeをインストールする。

udo apt install daemonize -y
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下のパッケージが新たにインストールされます:
  daemonize
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 2 個。
11.3 kB のアーカイブを取得する必要があります。
この操作後に追加で 39.9 kB のディスク容量が消費されます。
取得:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 daemonize amd64 1.7.7-1 [11.3 kB]
11.3 kB を 0秒 で取得しました (23.3 kB/s)
以前に未選択のパッケージ daemonize を選択しています。
(データベースを読み込んでいます ... 現在 48952 個のファイルとディレクトリがインストールされています。)
.../daemonize_1.7.7-1_amd64.deb を展開する準備をしています ...
daemonize (1.7.7-1) を展開しています...
daemonize (1.7.7-1) を設定しています ...
man-db (2.8.3-2ubuntu0.1) のトリガを処理しています ...

daemonizeはインストールできた。

 

次はdotnet-runtime-3.1。Microsoftのサイトを見る。

docs.microsoft.com

18.04 ✔️

APT を使用したインストールは、少ないコマンドで実行できます。 .NET をインストールする前に、次のコマンドを実行して、信頼されたキーの一覧に Microsoft パッケージ署名キーを追加し、パッケージ リポジトリを追加します。

ターミナルを開き、次のコマンドを実行します。

wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb()()
(中略)

.NET Core ランタイムを使用すると、ランタイムを含まない .NET Core を使用して作成されたアプリを実行できます。 次のコマンドを実行すると、.NET Core の最も互換性の高いランタイムである ASP.NET Core ランタイムがインストールされます。 ご利用のターミナルで、次のコマンドを実行します。

sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y aspnetcore-runtime-3.1

 

やってみる。 まず前半。

sudo dpkg -i packages-microsoft-prod.deb
以前に未選択のパッケージ packages-microsoft-prod を選択しています。
(データベースを読み込んでいます ... 現在 48957 個のファイルとディレクトリがインストールされています。)
packages-microsoft-prod.deb を展開する準備をしています ...
packages-microsoft-prod (1.0-ubuntu18.04.2) を展開しています...
packages-microsoft-prod (1.0-ubuntu18.04.2) を設定しています ...

 うまくいった。後半も実行。

sudo apt-get update; \
>   sudo apt-get install -y apt-transport-https && \
>   sudo apt-get update && \
do apt-g>   sudo apt-get install -y aspnetcore-runtime-3.1
ヒット:1 https://download.docker.com/linux/ubuntu bionic InRelease
取得:2 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
取得:3 https://packages.microsoft.com/ubuntu/18.04/prod bionic InRelease [4,002 B]
ヒット:4 http://archive.ubuntu.com/ubuntu bionic InRelease
取得:5 https://packages.microsoft.com/ubuntu/18.04/prod bionic/main amd64 Packages [139 kB]
取得:6 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
取得:7 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
395 kB を 2秒 で取得しました (201 kB/s)
パッケージリストを読み込んでいます... 完了
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
apt-transport-https はすでに最新バージョン (1.6.12ubuntu0.1) です。
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 2 個。
ヒット:1 https://download.docker.com/linux/ubuntu bionic InRelease
ヒット:2 https://packages.microsoft.com/ubuntu/18.04/prod bionic InRelease
取得:3 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
ヒット:4 http://archive.ubuntu.com/ubuntu bionic InRelease
取得:5 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
取得:6 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
252 kB を 2秒 で取得しました (145 kB/s)
パッケージリストを読み込んでいます... 完了
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
  dotnet-host dotnet-hostfxr-3.1 dotnet-runtime-3.1 dotnet-runtime-deps-3.1
以下のパッケージが新たにインストールされます:
  aspnetcore-runtime-3.1 dotnet-host dotnet-hostfxr-3.1 dotnet-runtime-3.1 dotnet-runtime-deps-3.1
アップグレード: 0 個、新規インストール: 5 個、削除: 0 個、保留: 2 個。
27.7 MB のアーカイブを取得する必要があります。
この操作後に追加で 91.3 MB のディスク容量が消費されます。
取得:1 https://packages.microsoft.com/ubuntu/18.04/prod bionic/main amd64 dotnet-host amd64 3.1.8-1 [32.9 kB]
取得:2 https://packages.microsoft.com/ubuntu/18.04/prod bionic/main amd64 dotnet-hostfxr-3.1 amd64 3.1.8-1 [121 kB]
取得:3 https://packages.microsoft.com/ubuntu/18.04/prod bionic/main amd64 dotnet-runtime-deps-3.1 amd64 3.1.8-1 [2,650 B]
取得:4 https://packages.microsoft.com/ubuntu/18.04/prod bionic/main amd64 dotnet-runtime-3.1 amd64 3.1.8-1 [21.8 MB]
取得:5 https://packages.microsoft.com/ubuntu/18.04/prod bionic/main amd64 aspnetcore-runtime-3.1 amd64 3.1.8-1 [5,770 kB]
27.7 MB を 4秒 で取得しました (6,602 kB/s)
以前に未選択のパッケージ dotnet-host を選択しています。
(データベースを読み込んでいます ... 現在 48965 個のファイルとディレクトリがインストールされています。)
.../dotnet-host_3.1.8-1_amd64.deb を展開する準備をしています ...
dotnet-host (3.1.8-1) を展開しています...
以前に未選択のパッケージ dotnet-hostfxr-3.1 を選択しています。
.../dotnet-hostfxr-3.1_3.1.8-1_amd64.deb を展開する準備をしています ...
dotnet-hostfxr-3.1 (3.1.8-1) を展開しています...
以前に未選択のパッケージ dotnet-runtime-deps-3.1 を選択しています。
.../dotnet-runtime-deps-3.1_3.1.8-1_amd64.deb を展開する準備をしています ...
dotnet-runtime-deps-3.1 (3.1.8-1) を展開しています...
以前に未選択のパッケージ dotnet-runtime-3.1 を選択しています。
.../dotnet-runtime-3.1_3.1.8-1_amd64.deb を展開する準備をしています ...
dotnet-runtime-3.1 (3.1.8-1) を展開しています...
以前に未選択のパッケージ aspnetcore-runtime-3.1 を選択しています。
.../aspnetcore-runtime-3.1_3.1.8-1_amd64.deb を展開する準備をしています ...
aspnetcore-runtime-3.1 (3.1.8-1) を展開しています...
dotnet-host (3.1.8-1) を設定しています ...
dotnet-runtime-deps-3.1 (3.1.8-1) を設定しています ...
dotnet-hostfxr-3.1 (3.1.8-1) を設定しています ...
dotnet-runtime-3.1 (3.1.8-1) を設定しています ...
aspnetcore-runtime-3.1 (3.1.8-1) を設定しています ...
man-db (2.8.3-2ubuntu0.1) のトリガを処理しています ...

インストールできた。

 

genieインストール

参照元ブログでは下記のコマンド。でもmakeできない。

 
cd genie
make install

shigeo@EAGLEII:/mnt/c/Users/shigeo-t$ cd genie/
shigeo@EAGLEII:/mnt/c/Users/shigeo-t/genie$ make install
make: *** ターゲット 'install' を make するルールがありません. 中止.

 

そこで、genieをソースからmakeするのではなく直インストールする作戦を調べることに。あった。

qiita.com

dotnet runtimeをセットアップしたのち、genieのインストール手順に従って、/etc/apt/sources.list.d/wsl-translinux.listというファイルを作成、以下の内容を記述して、

以下のコマンドを実行して systemd-genieのインストールをします。
sudo apt update
sudo apt install systemd-genie
これでgenieのセットアップは完了で、シェル上で
Ubuntu 18.04 LTS用
genie -c bash

# Arch等々
genie -s

# systemd起動確認
sudo systemctl status
と実行することで、新しくシェルが起動されてsystemdが起動出来ます。

 やってみる。

shigeo@EAGLEII:~$ sudo apt install systemd-genie
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下のパッケージが新たにインストールされます:
systemd-genie
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 2 個。
197 kB のアーカイブを取得する必要があります。
この操作後に追加で 660 kB のディスク容量が消費されます。
取得:1 https://wsl-translinux.arkane-systems.net/apt systemd-genie 1.28 [197 kB]
197 kB を 2秒 で取得しました (113 kB/s)
以前に未選択のパッケージ systemd-genie を選択しています。
(データベースを読み込んでいます ... 現在 49317 個のファイルとディレクトリがインストールされています。)
.../systemd-genie_1.28_amd64.deb を展開する準備をしています ...
systemd-genie (1.28) を展開しています...
systemd-genie (1.28) を設定しています ...
man-db (2.8.3-2ubuntu0.1) のトリガを処理しています ...

インストールできた。

 

Docker起動

 早速起動してみる。

shigeo@EAGLEII-wsl:~$ sudo systemctl start docker

確認する。まあ動いてる。

shigeo@EAGLEII-wsl:/mnt/c/Users/shigeo-t$ docker info
Client:
Debug Mode: false

Server:
Containers: 7
Running: 0
Paused: 0
Stopped: 7
Images: 62
Server Version: 19.03.13
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 4.19.128-microsoft-standard
Operating System: Ubuntu 18.04.5 LTS
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 24.73GiB
Name: EAGLEII-wsl
ID: MYOB:MVVY:IOQF:E2YE:IYCT:CYFN:767N:AEZ6:IPVX:NY4E:A34I:UA5H
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

Hello-worldを試す。

shigeo@EAGLEII-wsl:~$ docker run hello-world

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 run -it ubuntu bashも実行。

shigeo@EAGLEII-wsl:~$ docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
d72e567cc804: Pull complete
0f3630e5ff08: Pull complete
b6a83d81d1f4: Pull complete
Digest: sha256:bc2f7250f69267c9c6b66d7b6a81a54d3878bb85f1ebb5f951c896d13e6ba537
Status: Downloaded newer image for ubuntu:latest
root@10bb4e63d6df:/# id
uid=0(root) gid=0(root) groups=0(root)
root@10bb4e63d6df:/# exit
exit

問題無さそう。 

 

ということで、wsl export/importで増やしたディストリビューションでDockerを  というかsystemdが必要な人はこの手順で。

お時間あったら、他のエントリもクリックして頂ければ幸いです。