# [solved] lxc-container nginx net dependency

## mimosinnet

LXC container shows an ethernet device:

```
# ifconfig

eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.10.101  netmask 255.255.255.0  broadcast 192.168.10.255

        inet6 fe80::4c1f:85ff:fe41:b4c6  prefixlen 64  scopeid 0x20<link>

        ether 4e:1f:85:41:b4:c6  txqueuelen 1000  (Ethernet)

        RX packets 927855  bytes 619875039 (591.1 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 924704  bytes 62321627 (59.4 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
```

OpenRC nginx service fails to start in LXC container: 

```
# /etc/init.d/nginx start

 * Caching service dependencies ...                                                                                                                                                     [ ok ]

 * Bringing up interface eno1

 *   ERROR: interface eno1 does not exist

 *   Ensure that you have loaded the correct kernel module for your hardware

 * ERROR: net.eno1 failed to start

 * ERROR: cannot start nginx as net.eno1 would not start
```

Uncommenting the 'net' dependency in /etc/init.d/nginx...

 *Quote:*   

> depend() {
> 
>         # need net
> 
>         use dns logger netmount
> ...

 

... solves the issue:

```
# /etc/init.d/nginx start

 * Caching service dependencies ...                                                                                                                                                     [ ok ]

 * Checking nginx' configuration ...                                                                                                                                                    [ ok ]

 * Starting nginx ...  
```

Writing this post made me realise that there may be something wrong with the configuration of the lxc-container. I guess nginx should start without any issue. 

Cheers!

----------

## pa4wdh

I'm running some containers on a server here, including one running nginx. I think the problem is not nginx, but netifrc's way of checking the interface existence. It uses sysfs for that, and usually sysfs is not mounted in lxc's because it exposes information from the host. If you mount sysfs, you'll see the /etc/init.d/net.* scripts work as expected.

In most lxc's the network is already configured in the lxc configuration, so settiing config_eno1="null" in /etc/conf.d/net should be enough to get the dependency satisfied.

In my opinion it would be nice if netifrc could have a backup method to check interfaces in case sysfs is not mounted, /proc/net/dev is the first one i can think of.

----------

## mimosinnet

 *pa4wdh wrote:*   

> I think the problem is not nginx, but netifrc's way of checking the interface existence. It uses sysfs for that, and usually sysfs is not mounted in lxc's because it exposes information from the host. If you mount sysfs, you'll see the /etc/init.d/net.* scripts work as expected.

 

You diagnostic is right: nginx starts correctly after adding this line to the lxc configuration:

```
lxc.mount.entry=sysfs /var/lib/lxc/moodle2018/rootfs/sys sysfs defaults 0 0
```

The solution is perfect. Removing the previous entry and setting the network interface in the lxc-container as:

 *Quote:*   

> config_eno1="null"

 

Allows nginx service to start inside the container.

Thanks!

----------

## krinn

Did you guys tried to just disable it ?

I mean

```
/etc/conf.d/nginx

rc_depend="!net"

```

or in /etc/rc.conf

```
rc_nginx_depend="!net"

```

That should do the same as commenting out the "need net", but without hacking the ebuild each time it gets update.

----------

## mimosinnet

 *krinn wrote:*   

> 
> 
> ```
> /etc/conf.d/nginx
> 
> ...

 

Thanks for the hint! The above setting in the lxc-container works with nginx. Nevertheless, I get the same error with postgresql:

```
# /etc/init.d/postgresql-10 start

 * Bringing up interface eth0

 *   config_eth0 not specified; defaulting to DHCP

 *   dhcp ...

 *     Running udhcpc ...

udhcpc: started, v1.28.0

udhcpc: sending discover

udhcpc: sending discover

udhcpc: sending discover

udhcpc: no lease, failing

 *     start-stop-daemon: failed to start `/bin/busybox'                                                                                                                                [ !! ]

 * ERROR: net.eth0 failed to start

 * /run/postgresql: creating directory

 * /run/postgresql: correcting owner

 * Starting PostgreSQL 10 ...
```

Setting 'config_eth0="null"' in the container's '/etc/conf.d/net' works for nginx and postgresql.

Cheers!

----------

## krinn

of course, that was to point out openrc flexibility.

your solution works, as long as eth0 will keep that name  :Smile: 

----------

