container.execute() not working
See original GitHub issueI have flask application (flask + socketio + gunicorn), and pylxd not working correctly on it. Problem in container.execute() method.
For example
print(0)
container.execute(['ls'])
print(1)
container.execute(['cd', '/var/www/html'])
print(2)
container.execute(['service', 'nginx', 'restart'])
print(3)
Output: 0
Please help me 😦
pylxd = 2.2.10 lxd = 3.18
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
docker - Container is not running - Stack Overflow
To keep the container running in the background, try to run it with --detach (or -d ) argument. Save this answer.
Read more >How to Fix and Debug Docker Containers Like a Superhero
Container errors are tricky to diagnose, but some investigative magic works wonders. Read along to learn how to debug Docker containers.
Read more >How To Use docker exec to Run Commands in ... - DigitalOcean
When developing or deploying containers you'll often need to look inside a running container to inspect its current state or debug a problem...
Read more >How can I run a docker exec command inside a ... - Edureka
the docker command does not exist ... you can run any command in a running container just knowing its ID (or name):
Read more >Troubleshoot Cloud Run issues
Deployment errors. This section lists issues that you might encounter with deployment and provides suggestions for how to fix each of them. Container...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the update. The warnings are because LXD has grown some new attributes on some of the models, and pylxd is unaware of them. You can silence them by setting PYLXD_WARNINGS=‘none’ in the environment before running the app which loads pylxd.
This was added in #361 – by default one warning is printed for each attribute known about; there is an ‘always’ setting which prints the warning for every subsequent model load.
I think you are probably hitting #379 which I’m looking at. An (ugly) work-around is to use subprocess.Popen and just run lxc exec directly through that; but this only works if it is on the same machine and the user has the same permissions as the pylxd user that is being used.
I may provide that as an alternative exec method, but it has the above significant issues.
Popen(...)
by default connects the stdin, stdout and stderr to the parent process’ (i.e. your script’s) stdin / stdout. Therefore, theprint("OKKKKKK")
has no where to go. So if the command is still running on the container, then it is still holding the stdout and thus the print in the script will be buffered. What you really want to do is let the script run in the container that starts the service as a daemon and then exits. At least, I suspect that is what is going on.You only need to use
Popen(..)
if you want to communicate with the process as it is running. i.e. send it input, etc. Then you use the.communicate()
method after setting up the stdin, stdout, etc. to PIPEs to do that communication. If you are running one-shot commands, it’s easier to usesubprocess.check_call()
and friends.