accetto / ubuntu-vnc-xfce-g3

Headless Ubuntu/Xfce containers with VNC/noVNC (G3v6).
MIT License
214 stars 62 forks source link

Image doesn't quit after program returns 0 #27

Closed marisancans closed 2 years ago

marisancans commented 2 years ago

Lets say I run a docker image: docker run -p 49154:5901 -p 49153:6901 accetto/ubuntu-vnc-xfce-g3:latest-fugo /home/headless/run.sh

Where run.sh file contains a simple bash script:

#! /bin/bash

python3 /home/headless/clicker/test.py

And test.py contains:

import os 

print("Some jobs")
exit(1) // Here the docker image quits on any error larger than 0, but hangs / waits infinitely if the python script returns 0

Shouldn't the image be killed when command is executed also successfully?
How do I exit the image if the program is successful?

marisancans commented 2 years ago

The image also doesn't return the exit code from the run.sh file or any custom command passed

accetto commented 2 years ago

Hello,

this image is designed to keep running in the background by default. Please check the full Readme, especially the parts Running containers in background (detached), Running containers in foreground (interactively) and Startup options and help.

There are actually several ways how to make it to quit after running your command or script. I'll mention only some of them.

You can provide the --skip-startup option and your command/script as a parameter.

In the following example it's the whoami command, which is executed inside the container:

docker run accetto/ubuntu-vnc-xfce-g3 --skip-startup whoami

There are also other parameters you can use. You can list them by executing

docker run accetto/ubuntu-vnc-xfce-g3 -h (for concise help)

or

docker run accetto/ubuntu-vnc-xfce-g3 -H (for extended help)

You can also run the container interactively and let Docker to destroy it by providing the parameters -it --rm. Then type CTRL-C at the end and the container will be stopped and removed. Actually, the parameter -it ist optional.

docker run --rm docker run accetto/ubuntu-vnc-xfce-g3 whoami

docker run -it --rm docker run accetto/ubuntu-vnc-xfce-g3 whoami

The containers created from this image do not return anything by default, because they are intended for other kind of use.

However, you can do it easily by echoing your result like this:

docker run accetto/ubuntu-vnc-xfce-g3 --skip-startup echo "My result code is 999"

I hope I've helped you.

Best regards, accetto

accetto commented 2 years ago

No further actions from the requester. Closing the issue.