Run shell command after Gunicorn service starts in Docker containerrun a shell script and immediately background it, however keep the ability to inspect its outputRunning shell command and capturing the outputHow to list containers in DockerHow to remove old Docker containersRun a Docker Image as a ContainerCopying files from Docker container to hostCopying files from host to Docker containerFrom inside of a Docker container, how do I connect to the localhost of the machine?How do I run a command on an already existing Docker container?How do I get into a Docker container's shell?How do I edit a file after I shell to a Docker container?
Why does low tire pressure decrease fuel economy?
How should we understand "unobscured by flying friends" in this context?
I need to know information from an old German birth certificate
Why does PAUSE key have a long make code and no break code?
Contractor cut joist hangers to make them fit
Does the word voltage exist in academic engineering?
What makes things real?
Is mountain bike good for long distances?
A question regarding Buddhist world view and sense organs and their objects
Can you mark a new target with the Hunter's Mark spell if the original target shifts to a different plane?
How invisible hand adjusts stock prices if company is listed on multiple exchanges, under multiple currencies, and one of the currencies plunges?
Why is the the worst case for this function O(n*n)
How strong is aircraft-grade spruce?
Can multiple public keys lead to the same shared secret in x25519?
Yet another calculator problem
Is every sentence we write or utter either true or false?
Distinguishing between octahedral and tetrahedral holes
Who is the uncredited actor leading the squad in the Valerian movie?
2 load centers under 1 meter: do you need bonding and main breakers at both?
Bacteria vats to generate edible biomass, require intermediary species?
What can we do about our 9-month-old putting fingers down his throat?
Is it unavoidable taking shortcuts in software development sometimes?
Leaving the USA for 10 yrs when you have asylum
Did "Dirty Harry" feel lucky?
Run shell command after Gunicorn service starts in Docker container
run a shell script and immediately background it, however keep the ability to inspect its outputRunning shell command and capturing the outputHow to list containers in DockerHow to remove old Docker containersRun a Docker Image as a ContainerCopying files from Docker container to hostCopying files from host to Docker containerFrom inside of a Docker container, how do I connect to the localhost of the machine?How do I run a command on an already existing Docker container?How do I get into a Docker container's shell?How do I edit a file after I shell to a Docker container?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm running a simple Python Flask app using Gunicorn. I want to start the Gunicorn service then run a custom shell script after the service is up.
Something like this:
FROM python:3.6.5-slim
RUN apt-get update
&& apt-get clean
&& apt-get install -qq -y git build-essential libpq-dev --no-install-recommends
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["entrypoint.sh"]
With the objective being to run my_custom_script.sh
after the Gunicorn service starts (currently will not run):
#!/bin/sh
echo "Waiting for postgres..."
while ! nc -z postgres 5432; do
sleep 0.1
done
echo "PostgreSQL started"
gunicorn -b 0.0.0.0:5000 manage:app
bash my_custom_script.sh
The script just builds the databases, runs some tests and adds some fact data.
python docker gunicorn
|
show 4 more comments
I'm running a simple Python Flask app using Gunicorn. I want to start the Gunicorn service then run a custom shell script after the service is up.
Something like this:
FROM python:3.6.5-slim
RUN apt-get update
&& apt-get clean
&& apt-get install -qq -y git build-essential libpq-dev --no-install-recommends
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["entrypoint.sh"]
With the objective being to run my_custom_script.sh
after the Gunicorn service starts (currently will not run):
#!/bin/sh
echo "Waiting for postgres..."
while ! nc -z postgres 5432; do
sleep 0.1
done
echo "PostgreSQL started"
gunicorn -b 0.0.0.0:5000 manage:app
bash my_custom_script.sh
The script just builds the databases, runs some tests and adds some fact data.
python docker gunicorn
just to clarify something, usinggunicorn -b 0.0.0.0:5000 manage:app &
doesn't work?
– Arne
Mar 28 at 7:54
gunicorn -b 0.0.0.0:5000 manage:app is a long running process (it's the webserver) so never returns an exit code
– Jason Strimpel
Mar 28 at 7:56
That's why I added an ampersand at the end: stackoverflow.com/questions/44222883/…
– Arne
Mar 28 at 8:00
If you add an ampersand at the end of a command means, that it will be started in a subshell and the original process will continue with the next command. This will work. But it is a bad idea, because your gunicorn server will not be pid 1 in the container anymore. This will cause problems: For example it will not be possible to shut down the server in an orderly fashion.
– Carl Düvel
Mar 28 at 8:03
1
If there are steps needed in preparation: They can be run before in the script. If you want to test the application after it has been started - that would need to be done outside of the container.
– Carl Düvel
Mar 28 at 8:11
|
show 4 more comments
I'm running a simple Python Flask app using Gunicorn. I want to start the Gunicorn service then run a custom shell script after the service is up.
Something like this:
FROM python:3.6.5-slim
RUN apt-get update
&& apt-get clean
&& apt-get install -qq -y git build-essential libpq-dev --no-install-recommends
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["entrypoint.sh"]
With the objective being to run my_custom_script.sh
after the Gunicorn service starts (currently will not run):
#!/bin/sh
echo "Waiting for postgres..."
while ! nc -z postgres 5432; do
sleep 0.1
done
echo "PostgreSQL started"
gunicorn -b 0.0.0.0:5000 manage:app
bash my_custom_script.sh
The script just builds the databases, runs some tests and adds some fact data.
python docker gunicorn
I'm running a simple Python Flask app using Gunicorn. I want to start the Gunicorn service then run a custom shell script after the service is up.
Something like this:
FROM python:3.6.5-slim
RUN apt-get update
&& apt-get clean
&& apt-get install -qq -y git build-essential libpq-dev --no-install-recommends
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["entrypoint.sh"]
With the objective being to run my_custom_script.sh
after the Gunicorn service starts (currently will not run):
#!/bin/sh
echo "Waiting for postgres..."
while ! nc -z postgres 5432; do
sleep 0.1
done
echo "PostgreSQL started"
gunicorn -b 0.0.0.0:5000 manage:app
bash my_custom_script.sh
The script just builds the databases, runs some tests and adds some fact data.
python docker gunicorn
python docker gunicorn
asked Mar 28 at 7:28
Jason StrimpelJason Strimpel
4,97712 gold badges52 silver badges85 bronze badges
4,97712 gold badges52 silver badges85 bronze badges
just to clarify something, usinggunicorn -b 0.0.0.0:5000 manage:app &
doesn't work?
– Arne
Mar 28 at 7:54
gunicorn -b 0.0.0.0:5000 manage:app is a long running process (it's the webserver) so never returns an exit code
– Jason Strimpel
Mar 28 at 7:56
That's why I added an ampersand at the end: stackoverflow.com/questions/44222883/…
– Arne
Mar 28 at 8:00
If you add an ampersand at the end of a command means, that it will be started in a subshell and the original process will continue with the next command. This will work. But it is a bad idea, because your gunicorn server will not be pid 1 in the container anymore. This will cause problems: For example it will not be possible to shut down the server in an orderly fashion.
– Carl Düvel
Mar 28 at 8:03
1
If there are steps needed in preparation: They can be run before in the script. If you want to test the application after it has been started - that would need to be done outside of the container.
– Carl Düvel
Mar 28 at 8:11
|
show 4 more comments
just to clarify something, usinggunicorn -b 0.0.0.0:5000 manage:app &
doesn't work?
– Arne
Mar 28 at 7:54
gunicorn -b 0.0.0.0:5000 manage:app is a long running process (it's the webserver) so never returns an exit code
– Jason Strimpel
Mar 28 at 7:56
That's why I added an ampersand at the end: stackoverflow.com/questions/44222883/…
– Arne
Mar 28 at 8:00
If you add an ampersand at the end of a command means, that it will be started in a subshell and the original process will continue with the next command. This will work. But it is a bad idea, because your gunicorn server will not be pid 1 in the container anymore. This will cause problems: For example it will not be possible to shut down the server in an orderly fashion.
– Carl Düvel
Mar 28 at 8:03
1
If there are steps needed in preparation: They can be run before in the script. If you want to test the application after it has been started - that would need to be done outside of the container.
– Carl Düvel
Mar 28 at 8:11
just to clarify something, using
gunicorn -b 0.0.0.0:5000 manage:app &
doesn't work?– Arne
Mar 28 at 7:54
just to clarify something, using
gunicorn -b 0.0.0.0:5000 manage:app &
doesn't work?– Arne
Mar 28 at 7:54
gunicorn -b 0.0.0.0:5000 manage:app is a long running process (it's the webserver) so never returns an exit code
– Jason Strimpel
Mar 28 at 7:56
gunicorn -b 0.0.0.0:5000 manage:app is a long running process (it's the webserver) so never returns an exit code
– Jason Strimpel
Mar 28 at 7:56
That's why I added an ampersand at the end: stackoverflow.com/questions/44222883/…
– Arne
Mar 28 at 8:00
That's why I added an ampersand at the end: stackoverflow.com/questions/44222883/…
– Arne
Mar 28 at 8:00
If you add an ampersand at the end of a command means, that it will be started in a subshell and the original process will continue with the next command. This will work. But it is a bad idea, because your gunicorn server will not be pid 1 in the container anymore. This will cause problems: For example it will not be possible to shut down the server in an orderly fashion.
– Carl Düvel
Mar 28 at 8:03
If you add an ampersand at the end of a command means, that it will be started in a subshell and the original process will continue with the next command. This will work. But it is a bad idea, because your gunicorn server will not be pid 1 in the container anymore. This will cause problems: For example it will not be possible to shut down the server in an orderly fashion.
– Carl Düvel
Mar 28 at 8:03
1
1
If there are steps needed in preparation: They can be run before in the script. If you want to test the application after it has been started - that would need to be done outside of the container.
– Carl Düvel
Mar 28 at 8:11
If there are steps needed in preparation: They can be run before in the script. If you want to test the application after it has been started - that would need to be done outside of the container.
– Carl Düvel
Mar 28 at 8:11
|
show 4 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392209%2frun-shell-command-after-gunicorn-service-starts-in-docker-container%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392209%2frun-shell-command-after-gunicorn-service-starts-in-docker-container%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
just to clarify something, using
gunicorn -b 0.0.0.0:5000 manage:app &
doesn't work?– Arne
Mar 28 at 7:54
gunicorn -b 0.0.0.0:5000 manage:app is a long running process (it's the webserver) so never returns an exit code
– Jason Strimpel
Mar 28 at 7:56
That's why I added an ampersand at the end: stackoverflow.com/questions/44222883/…
– Arne
Mar 28 at 8:00
If you add an ampersand at the end of a command means, that it will be started in a subshell and the original process will continue with the next command. This will work. But it is a bad idea, because your gunicorn server will not be pid 1 in the container anymore. This will cause problems: For example it will not be possible to shut down the server in an orderly fashion.
– Carl Düvel
Mar 28 at 8:03
1
If there are steps needed in preparation: They can be run before in the script. If you want to test the application after it has been started - that would need to be done outside of the container.
– Carl Düvel
Mar 28 at 8:11