0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

systemd-nspawnAdvent Calendar 2018

Day 4

Hyper-V + systemd-nspawnの開発環境を作る(3) ~ コンテナ作成 ~

Last updated at Posted at 2018-12-14

前回の続き

コンテナの作成

ubuntuのコンテナを作成します

apt install -y systemd-container debootstrap
cd /var/lib/machines/
debootstrap --arch amd64 bionic ./ubuntu http://archive.ubuntu.com/ubuntu
curl -L https://git.io/fpbnu > ubuntu/etc/systemd/network/80-container-host0.network
curl -L https://git.io/fpbn2 > ubuntu/etc/systemd/resolved.conf
echo ubuntu-guest > ubuntu/etc/hostname
perl -i -ple 's/^(127.0.0.1\slocalhost).*/$1 ubuntu-guest/' ubuntu/etc/hosts

コンテナ内での設定

以下のコマンドでコンテナに入ります

systemd-nspawn -D ./ubuntu

コンテナ内で以下設定をします

# ↓はコンテナ内で打つコマンド
    passwd
    # 好きなパスワードを設定する
    apt remove -y netplan.io
    systemctl enable systemd-networkd
    exit
# ↑ここまでコンテナ内

起動

以下のコマンドで通常のマシンのようにbootします

systemd-nspawn -D ./ubuntu --network-bridge br0 -b

起動したら先ほど設定したrootアカウントのパスワードで入ります

# 疎通確認用のnginxを入れます
apt update
apt install -y nginx
echo ubuntu1 > /var/www/html/index.nginx-debian.html

この状態で http://10.100.0.3/ にアクセスしてubuntu1の文字が見えたらOKです

終了

systemctl halt

次回

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?