Linucメモ⑧KVM仮想マシン、Docker編

KVM仮想マシンの操作

KVM (Kernel-based Virtual Machine:カーネルベースの仮想マシン) は、
LInux上で仮想マシンを動かすためのソフトウェアです。

CPUの仮想化支援機能

Intel VT、AMD-Vどちらかの仮想化支援機能搭載のホストマシンでないと、
仮想マシン構築はできない模様・・・・。

virshコマンド

  • resume 仮想マシンを再開

  • supend 仮想マシンを一時停止

  • dumpxml 仮想マシンの定義ファイルをXML形式で出力

  • create ↑で出力したXMLファイルから仮想マシンを生成し、新規の仮想マシンを起動

  • shutdown 仮想マシンを正常に終了

  • destroy 仮想マシンを強制終了

Docker環境構築

Dockerの勉強するために、以下のサイトを参考にDocker環境を構築しました。環境構築自体は本試験範囲ではないですが、いつか役に立つと思われる内容なので、こちらに記載しておきます。

参考サイト
WEB ARCH LABO
Docker CEを Ubuntu 16.04 TLS (Xenial Xerus) にaptインストールする手順
https://weblabo.oscasierra.net/docker-ce-install-ubuntu1604/

root@Ubuntu-LInuc:~# sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
ca-certificates is already the newest version (20230311ubuntu0.22.04.1).
software-properties-common is already the newest version (0.99.22.7).
software-properties-common set to manually installed.
apt-transport-https is already the newest version (2.4.9).
The following NEW packages will be installed:
  curl gnupg-agent
0 upgraded, 2 newly installed, 0 to remove and 55 not upgraded.
Need to get 200 kB of archives.
After this operation, 501 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://jp.archive.ubuntu.com/ubuntu jammy-updates/main amd64 curl amd64 7.81.0-1ubuntu1.10 [194 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 gnupg-agent all 2.2.27-3ubuntu2.1 [5,484 B]

root@Ubuntu-LInuc:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
root@Ubuntu-LInuc:~# sudo apt-key fingerprint 0EBFCD88
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

root@Ubuntu-LInuc:~# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Repository: 'deb [arch=amd64] https://download.docker.com/linux/ubuntu jammy stable'
Description:
Archive for codename: jammy components: stable
More info: https://download.docker.com/linux/ubuntu
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
Adding deb entry to /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-jammy.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-jammy.list
Get:1 https://download.docker.com/linux/ubuntu jammy InRelease [48.9 kB]
Get:2 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages [20.4 kB]
Hit:3 http://jp.archive.ubuntu.com/ubuntu jammy InRelease
Fetched 69.3 kB in 1s (71.0 kB/s)
Reading package lists... Done
W: https://download.docker.com/linux/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.

root@Ubuntu-LInuc:~# sudo apt-get update
Hit:1 https://download.docker.com/linux/ubuntu jammy InRelease
Reading package lists... Done
W: https://download.docker.com/linux/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
root@Ubuntu-LInuc:~# sudo apt-get install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  docker-buildx-plugin docker-ce-rootless-extras docker-compose-plugin git
  git-man liberror-perl pigz slirp4netns
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite git-daemon-run | git-daemon-sysvinit
  git-doc git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn
The following NEW packages will be installed:
  containerd.io docker-buildx-plugin docker-ce docker-ce-cli
  docker-ce-rootless-extras docker-compose-plugin git git-man liberror-perl
  pigz slirp4netns
0 upgraded, 11 newly installed, 0 to remove and 55 not upgraded.
Need to get 118 MB of archives.
After this operation, 435 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://download.docker.com/linux/ubuntu jammy/stable amd64 containerd.io amd64 1.6.21-1 [28.3 MB]
Get:2 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-buildx-plugin amd64 0.11.1-1~ubuntu.22.04~jammy [28.2 MB]
Get:3 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-cli amd64 5:24.0.4-1~ubuntu.22.04~jammy [13.3 MB]
Get:4 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce amd64 5:24.0.4-1~ubuntu.22.04~jammy [22.9 MB]
Fetched 118 MB in 6s (20.0 MB/s)
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Setting up git (1:2.34.1-1ubuntu1.9) ...
Processing triggers for man-db (2.10.2-1) ...

root@Ubuntu-LInuc:~# docker -v
Docker version 24.0.4, build 3713ee1

コンテナ起動

docker run centos:7 cat /etc/hostname

動作確認
docker ps 動作中のコンテナ確認
docker ps -a 終了したコンテナも含めて確認

コンテナ削除

docker rm コンテナID

コンテナ停止

docker stop コンテナ停止
docker kill コンテナ強制停止

Docker Hub

docker push イメージをアップロード
docker pull イメージをダウンロード

その他

  • docker images dockerに保存したイメージ確認

root@Ubuntu-LInuc:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
centos       7         eeb6ee3f44bd   22 months ago   204MB
  • docker attach コンテナの標準入出力に接続する

この記事が気に入ったらサポートをしてみませんか?