それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

lxc内部 でdocker を動かしたときのメモ。

Ubuntu のLXCでdockerを動かしたときのメモ

UbuntuのLXCで ubuntuを動かしてその中で、dockerを動かした。

lxc ubuntuを作る

最初に lxc のストレージを作る

lxc storage create bt01 btrfs

作ったストレージ内部にUbuntuを作る

lxc launch ubuntu:22.04 docker-host --storage bt01

LXCの権限を引き上げる。Vmのネスティングを有効にする。

lxc config set docker-host security.privileged true
lxc config set docker-host security.nesting true
lxc restart docker-host

dockerをubuntu on lxc に つくる

lxc に入って、Dockerをインストールする。

lxc shell docker-host

ubuntu に apt 経由で dockerを入れる。

sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

動作チェック

sudo docker run hello-world

動作チェックの結果

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:

docker をメンテナンス

 docker images
REPOSITORY          TAG       IMAGE ID       CREATED       SIZE
hello-world         latest    b038788ddb22   2 weeks ago   9.14kB

ubuntuのストレージをチェック

hello-worldは消しておく。

docker rm 5caa83a5f5df
docker image rm hello-world

lxc なら 2GBで動くの便利ですね。

root@docker-host:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/loop9      9.0G  2.0G  6.7G  23% /
none            492K  4.0K  488K   1% /dev
tmpfs           100K     0  100K   0% /dev/lxd
tmpfs           100K     0  100K   0% /dev/.lxd-mounts
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           1.6G  300K  1.6G   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
snapfuse         60M   60M     0 100% /snap/core20/1826
snapfuse        110M  110M     0 100% /snap/lxd/24326
snapfuse         44M   44M     0 100% /snap/snapd/18363
tmpfs           786M  4.0K  786M   1% /run/user/0
overlay         9.0G  2.0G  6.7G  23% /var/lib/docker/overlay2/46de0bd4b99f36fbb16e5657c29a0b508fbe71e288b3564827c76eb10efdbf60/merged