Skip to content
Advertisement

uWSGI server does not run with & argument

I build a docker image which runs flask on an uWSGI server. I have a uwsgi.ini file with configuration. When I use

CMD ["uwsgi", "--ini", "uwsgi.ini"]

in the Dockerfile, everything works fine and the server runs, I can access my flask app via the browser. The only problem is that I cannot use the container’s bash while it’s running, as it is blocked by the uWSGI process. I found that appending an & should make the uWSGI run in the background. However, when I use

CMD ["uwsgi", "--ini", "uwsgi.ini", "&"]

I get an error saying

unable to load configuration from &

I get that when I try this, the uWSGI thinks I’m passing another argument that it should process. However, I cannot find any way to tell it that it is not the case. Using docker run with the -d argument also only detaches the container from the current terminal on the host, but when I use docker attach, I get a bash that I can’t do anything with.

Is there a way to tell uWSGI explicitly that I want it to run in the background? Am I missing something?

Advertisement

Answer

You can execute a command on your container by using the exec command.

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
9fb488c77d55        nginx               "/docker-entrypoint.…"   18 minutes ago      Up 18 minutes       80/tcp              distracted_brown

so here I have an nginx container image running in a container called distracted_brown. So I can ask the container to run a command using exec. In this case the command i want to run is the shell sh. I also pass the -it flag so i can run interactivly with STDIN and STDOUT

docker container exec -it distracted_brown sh

this will allow me shell access to the container where nginx is running as PID 1. As a side note you dont normally want to run your CMD process in the background as when PID 1 closes the container will close.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement