2019年1月11日金曜日

lxd containerに関するメモ

container  ubuntu18

lxdはlxcを使いやすくしたもの

インストール
sudo apt instasll lxd
snap install lxd

初期化
lxd init
いろいろ設定項目があるが、すべてdefaultで大丈夫
 
下記のエラーが出力される場合は、
 Error: Failed to connect to local LXD: Get http://unix.socket/1.0: dial unix  /var/snap/lxd/common/lxd/unix.socket: connect: permission denied

idコマンドでlxdグループが追加されているか確認し、
ない場合は、
usermod -aG lxd USER名
でグループを追加しlogoff/loginする。(exec $SHELL -l)


コンテナの作成
lxc launch ubuntu:18.04 ub18  
 (lxc launch ubuntu:20.10 ub201)
  ub18は、任意のコンテナの名前

コンテナのリスト表示
lxc list
コンテナのイメージのリスト
lxc image list
コンテナの情報
lxc info コンテナの名前

コンテナの起動 lxc start ub18

コンテナの接続 lxc exec ub18 -- bash

コンテナの停止 lxc stop ub18
コンテナの削除 lxc delete ub18


lxc file pull
lxc file push

fedora28のイメージをダウンロードしてコンテナを作るのは
lxc launch images:fedora/28/amd64 fe28

snapshotの作成
lxc snapshot ub18 20190120

コンテナ内のウエブサイト等を外部に公開する。
host側のnicに公開用のaddressを追加
ip a add 192.168.0.88/24 dev enp0s10
公開用のアドレスとコンテナのアドレスを接続する。
sudo iptables -t nat -A PREROUTING -p tcp -d 192.168.0.88 -i enp0s10 --dport 80 -j DNAT --to-destination 240.82.0.47:80

リモートサーバ名
lxc remote list

イメージのリスト
lxc image list ubuntu:

LXD にはデフォルトでイメージを提供するリモートサーバが 3 つ登録されています:

ubuntu: (stable Ubuntu イメージ用 )
ubuntu-daily: (daily Ubuntu イメージ用 )
images: (その他の多数のディストリビューション用)

イメージの作り方
snapshotを作成してpublishする。


ホストとターゲットの共有フォルダの作成
lxc config device add container-name home disk source=/home/share path=/home/share
homeは適当な名前
/home/shareは適当なディレクトリ


sshを使う場合

/etc/ssh/sshd_config
を編集
PasswordAuthentication yes
とし
systemctl restart sshd


lxd -h
  activateifneeded   Check if LXD should be started
  help               Help about any command
  import             Import existing containers
  init               Configure the LXD daemon
  shutdown           Tell LXD to shutdown all containers and exit
  version            Show the server version
  waitready          Wait for LXD to be ready to process requests

lxc -h
  alias       Manage command aliases
  cluster     Manage cluster members
  config      Manage container and server configuration options
  console     Attach to container consoles
  copy        Copy containers within or in between LXD instances
  delete      Delete containers and snapshots
  exec        Execute commands in containers
  export      Export container backups
  file        Manage files in containers
  help        Help about any command
  image       Manage images
  import      Import container backups
  info        Show container or server information
  launch      Create and start containers from images
  list        List containers
  move        Move containers within or in between LXD instances
  network     Manage and attach containers to networks
  operation   List, show and delete background operations
  profile     Manage profiles
  project     Manage projects
  publish     Publish containers as images
  remote      Manage the list of remote servers
  rename      Rename containers and snapshots
  restart     Restart containers
  restore     Restore containers from snapshots
  snapshot    Create container snapshots
  start       Start containers
  stop        Stop containers
  storage     Manage storage pools and volumes
  version     Show local and remote versions

0 件のコメント:

コメントを投稿