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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현