20
20

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.

dockerにlxc-confで固定IPを割り振る

Last updated at Posted at 2015-02-15

参考

ホスト側の準備

ブリッジインターフェイス(br0とbr1)を作っておく。

/etc/sysconfig/docker-network
- DOCKER_NETWORK_OPTIONS=
+ DOCKER_NETWORK_OPTIONS="-b none -e lxc"
systemctl restart docker

コンテナ起動オプション

ネットワーク設定
docker run -it -d \
  \
 --lxc-conf="lxc.network.type = veth" \
 --lxc-conf="lxc.network.flags = up" \
 --lxc-conf="lxc.network.link = br0" \
 --lxc-conf="lxc.network.ipv4 = 192.168.100.4/24" \
 --lxc-conf="lxc.network.ipv4.gateway = 192.168.100.1" \
 --lxc-conf="lxc.network.name = eth0" \
 \
 --lxc-conf="lxc.network.type = veth" \
 --lxc-conf="lxc.network.flags = up" \
 --lxc-conf="lxc.network.link = br1" \
 --lxc-conf="lxc.network.ipv4 = 192.168.0.4/24" \
 --lxc-conf="lxc.network.name = eth1" \
 \
 tukiyo3/centos5-mine

これで192.168.100.4192.168.0.4にpingが通るようになる。

コンテナに入り方

# docker exec -it d3 /bin/bash
FATA[0000] Error response from daemon: Unsupported: Exec is not supported by the lxc driver

lxc driverを使うとdocker execでコンテナに入れない。(1.4.1の場合。docker 1.5だと入れるっぽい。)

nsenterを使う。

Pid確認してnsenterで入る
# docker inspect d3 | grep Pid
        "Pid": 4002,
# nsenter -t 4002 -m -u -i -n -p -- /bin/bash
bash-3.2#

sshdを起動

dockerコンテナ内にて作業
bash-3.2# yum install -y openssh-server
bash-3.2# /sbin/service sshd start
bash-3.2# mkdir ~/.ssh
bash-3.2# cat > authorized_keys<<EOF
(キーを登録)
EOF
$ ssh root@192.168.100.4

接続ができることを確認。

nsenterで入った場合、PATHに/binと/sbinが入っていない問題

cp -a /etc/profile.d/krb5-devel.sh /etc/profile.d/nsenter.sh
/bin/sed -i -e 's@/usr/kerberos@:@g' /etc/profile.d/nsenter.sh
/bin/sed -i -e 's@PATH=:@PATH=@' /etc/profile.d/nsenter.sh
chmod +x /etc/profile.d/nsenter.sh
20
20
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
20
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?