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;








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.










share|improve this question
























  • 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

















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.










share|improve this question
























  • 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













0












0








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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, 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

















  • 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
















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












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
);



);














draft saved

draft discarded
















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.




















draft saved

draft discarded















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?