6

I am using Fedora 20 in a VM and trying to learn to use containers. I have created a container but can't start it. Here is the terminal output:

[root@localhost home]# lxc-start -n test
lxc-start: conf.c: instantiate_veth: 2978 failed to attach 'veth87VSIJ' to the bridge 'virbr0': No such device
lxc-start: conf.c: lxc_create_network: 3261 failed to create netdev
lxc-start: start.c: lxc_spawn: 826 failed to create the network
lxc-start: start.c: __lxc_start: 1080 failed to spawn 'test'
lxc-start: lxc_start.c: main: 342 The container failed to start.
lxc-start: lxc_start.c: main: 346 Additional information can be obtained by setting the --logfile and --logpriority options.
[root@localhost home]# 
1
  • please choose the best correct answer!
    – rleir
    May 21, 2017 at 4:42

4 Answers 4

11

Make sure libvirtd is installed and running (via the libvirt package). e.g.:

$ yum install -y libvirt
$ systemctl start libvirtd
$ brctl show
bridge name bridge id       STP enabled interfaces
virbr0      8000.fea2866efadb   yes     veth7ATCJK
1
  1. change your network hwaddr (on config container file)
  2. set ip of your bridge and make it up

its same with http://febru.soluvas.com/2015/03/solved-failed-to-attach-bridge-virbr0.html

1

The error message

lxc-start: conf.c: instantiate_veth: 2978 failed to attach 'veth87VSIJ' to the bridge 'virbr0': No such device

clearly indicates the absence of the bridge interface on your system. You can check your current available interfaces using the commands

ifconfig

or

ip link

In the current case because you don't have the bridge enabled, another thing to know is that virbr0 is generally associated with visualization services like xen or libvirtd. So the first thing you can try is to start one of those (being in fedora 20 I think you're using libvirtd)

sudo systemctl start libvirtd

If the interface is not activated by this, you can simply add it manually, but I strongly advise against it to avoid configuration conflicts.

The better solution that I may suggest is to use a different bridge altogether as it will also give you more control over it configuration. First you have to identify where the lxc-net bridge name is set, by examining the /usr/libexec/lxc/lxc-net

#!/bin/sh -

distrosysconfdir="/etc/sysconfig"
varrun="/run/lxc"
varlib="/var/lib"

# These can be overridden in /etc/sysconfig/lxc
#   or in /etc/sysconfig/lxc-net

USE_LXC_BRIDGE="true"
LXC_BRIDGE="lxcbr0"
LXC_ADDR="10.0.3.1"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="10.0.3.0/24"
LXC_DHCP_RANGE="10.0.3.2,10.0.3.254"
LXC_DHCP_MAX="253"
LXC_DHCP_CONFILE=""
LXC_DOMAIN=""

LXC_IPV6_ADDR=""
LXC_IPV6_MASK=""
LXC_IPV6_NETWORK=""
LXC_IPV6_NAT="false"

[ ! -f $distrosysconfdir/lxc ] || . $distrosysconfdir/lxc

which will be overridden by /etc/lxc/default.conf

lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:xx:xx:xx

only if USE_LXC_BRIDGE="true" in /etc/sysconfig/lxc (not the case here)

# LXC_AUTO - whether or not to start containers at boot
LXC_AUTO="true"

# BOOTGROUPS - What groups should start on bootup?
#   Comma separated list of groups.
#   Leading comma, trailing comma or embedded double
#   comma indicates when the NULL group should be run.
# Example (default): boot the onboot group first then the NULL group
BOOTGROUPS="onboot,"

# SHUTDOWNDELAY - Wait time for a container to shut down.
#   Container shutdown can result in lengthy system
#   shutdown times.  Even 5 seconds per container can be
#   too long.
SHUTDOWNDELAY=5

# OPTIONS can be used for anything else.
#   If you want to boot everything then
#   options can be "-a" or "-a -A".
OPTIONS=

# STOPOPTS are stop options.  The can be used for anything else to stop.
#   If you want to kill containers fast, use -k
STOPOPTS="-a -A -s"

USE_LXC_BRIDGE="false"  # overridden in lxc-net

[ ! -f /etc/sysconfig/lxc-net ] || . /etc/sysconfig/lxc-net

or /etc/sysconfig/lxc-net if it exists (not in my case). In my case the bridge name is lxcbr0 and it will not be using the lxc bridge configuration.

With that settled, we create the new bridge interface configuration with:

sudo sh -c '
cat > /etc/sysconfig/network-scripts/ifcfg-lxcbr0 <<EOF
DEVICE="lxcbr0"
BOOTPROTO="static"
IPADDR="192.168.1.250"
NETMASK="255.255.255.0"
ONBOOT="yes"
TYPE="Bridge"
NM_CONTROLLED="no"
EOF
'

and we start it with

sudo ifup lxcbr0

you will also have to restart lxc and lxc-net

sudo systemctl stop lxc

sudo systemctl stop lxc-net

sudo systemctl start lxc-net

sudo systemctl start lxc

0

If you have docker installed lxc guests can also use the docker0 bridge:

In /var/lib/lxc/container/config set

lxc.network.link = docker0
lxc.start.auto = 1

& give the guest a static ip address in the file inside the container:

/etc/sysconfig/network-scripts/ifcfg-eth0 

DEVICE=eth0
ONBOOT=yes
HOSTNAME=
NM_CONTROLLED=no
TYPE=Ethernet
MTU=
DHCP_HOSTNAME=centos6
BOOTPROTO="static"
IPADDR=172.17.xx.xx
NETMASK=255.255.255.0
GATEWAY=172.17.xx.1    # check ifconfig on the host for the docker0 ip

enable the lxc service & guests will autostart with networking:

systemctl enable lxc.service

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .