lxc / go-lxc

Go bindings for liblxc
https://linuxcontainers.org/lxc
Other
428 stars 77 forks source link

Execute method always fails #58

Closed sethdmoore closed 6 years ago

sethdmoore commented 8 years ago

No matter how you invoke it, the Execute method fails.

The example in the v2 branch of the project folder fails, since it does not first create a container

$ go run examples/execute.go
2016/04/18 20:56:01 ERROR: executing the command in a temporary container failed

Here is a code example using NewContainer, Create and Execute method. Always fails with "container already defined" https://gist.github.com/sethdmoore/bf4d6e332ec1418c567ddfc9294bd9c6

This is due to the check on these lines: https://github.com/lxc/go-lxc/blob/v2/container.go#L457-L459

According to the lxc-execute(1) man page, " lxc-execute runs the specified command inside the container specified by name. It will setup the container according to the configuration previously defined with the lxc-create command or with the configuration file parameter."

lxc-execute(1) without lxc-create first fails on my machine

$ lxc-execute --name foo -- ls /
lxc-execute: conf.c: mount_autodev: 1175 No such file or directory - Failed mounting tmpfs onto /dev
lxc-execute: conf.c: tmp_proc_mount: 3678 No such file or directory - failed to mount /proc in the container.
lxc-execute: lsm/apparmor.c: apparmor_process_label_set: 183 No such file or directory - failed to change apparmor profile to lxc-container-default
lxc-execute: sync.c: __sync_wait: 51 invalid sequence number 1. expected 4
lxc-execute: start.c: __lxc_start: 1213 failed to spawn 'foo'
lxc-execute: cgmanager.c: cgm_remove_cgroup: 523 call to cgmanager_remove_sync failed: invalid request
lxc-execute: cgmanager.c: cgm_remove_cgroup: 525 Error removing all:lxc/foo-3

If I create the container first, it works

lxc-create --name foo -t /usr/share/lxc/templates/lxc-alpine &>/dev/null && lxc-execute --name foo -- ls /
init.lxc.static: initutils.c: mount_fs: 36 failed to mount /proc : Operation not permitted
init.lxc.static: initutils.c: mount_fs: 36 failed to mount /dev/shm : Operation not permitted
init.lxc.static: initutils.c: mount_fs: 36 failed to mount /dev/mqueue : Operation not permitted
bin              etc              init.lxc.static  linuxrc          mnt              root             sbin             tmp              var
dev              home             lib              media            proc             run              sys              usr

System / Package / Etc below

~/go/src/gopkg.in/lxc/go-lxc.v2 $ git rev-parse HEAD
85d46fc661f9628f265f3f4df15427d15c272e8a

$ go version
go version go1.6.1 linux/amd64

$ uname -a
Linux example.com 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 15.10
Release:        15.10
Codename:       wily

apt-cache policy lxc lxc-dev
lxc:
  Installed: 1.1.5-0ubuntu0.15.10.3
  Candidate: 1.1.5-0ubuntu0.15.10.3
  Version table:
 *** 1.1.5-0ubuntu0.15.10.3 0
        500 http://mirrors.digitalocean.com/ubuntu/ wily-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     1.1.4-0ubuntu1 0
        500 http://mirrors.digitalocean.com/ubuntu/ wily/main amd64 Packages
lxc-dev:
  Installed: 1.1.5-0ubuntu0.15.10.3
  Candidate: 1.1.5-0ubuntu0.15.10.3
  Version table:
 *** 1.1.5-0ubuntu0.15.10.3 0
        500 http://mirrors.digitalocean.com/ubuntu/ wily-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     1.1.4-0ubuntu1 0
        500 http://mirrors.digitalocean.com/ubuntu/ wily/main amd64 Packages
hallyn commented 7 years ago

Just a minor correction, you don't actually need to first create the container for execute to work, but you need to provide some configuration, for instance

lxc-execute -n u1 -s lxc.rootfs=./rootfs -s lxc.network.type=none -- /bin/sh

caglar10ur commented 6 years ago

I believe https://github.com/lxc/go-lxc/commit/89b06ca6fad6daea5a72a1f47e69e39716c46198 fixed this issue. Closing now.