I want to execute a command inside an existing lxc without going through the regular Linux init. lxc-execute command is for that I guess but I get the following error when I run this command on my existing test lxc.

sudo lxc-execute -n test -- service apache2 start 

I get following error:

lxc-execute: Failed to find an lxc-init
lxc-execute: invalid sequence number 1. expected 4
lxc-execute: failed to spawn 'test'

2 Answers 2


Have you tried lxc-attach instead? According the documentation,

lxc-attach - start a process inside a running container.

Example to list all folders inside home of the container

lxc-attach -n myContainer -- ls -lh /home

If no process is defined, it creates a new shell inside the container.

  • The thing with lxc-attach is that you can't use it with less, e.g. lxc-attach -n c1 -- dmesg | less. The output is similar to what you get with docker-compose exec ... | less unless you pass -T.
    – x-yuri
    Jul 21, 2021 at 15:30

lxc-execute is designed to create and run and lxc container and execute the command. So it can not be used to execute a command currently setup and started one.

Quotation from Serge E. Hallyn @ https://www.mail-archive.com/lxc-users@lists.sourceforge.net/msg00134.html

Moving an existing process into an existing, populated namespace will likely never be possible.

You may try Ullrich Horlacher's lxc command but currently the page is out of order. Process is described in this post:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.