How to Get Docker Commands to Run in the Background with Nohup

How to get docker commands to run in the background with nohup

From the docker exec documentation page https://docs.docker.com/engine/reference/commandline/exec/

--interactive , -i      Keep STDIN open even if not attached
--tty , -t Allocate a pseudo-TTY

I guess removing both the -i and -t flags would probably be sufficient

nohup service inside docker container

Skip all the effort to nohup and background, instead just detach from the process (note the -d):

sudo docker exec -itd php7-fpm bash -c 'php /www/site/artisan queue:listen'

shell script to execute a nohup task inside a docker

The below way of scripting works for me!!!!!!!!!

ex=' /opt/kafka/bin/connect-standalone.sh /opt/kafka/config/connect-standalone-mongo.properties  /opt/kafka/config/connect-mongo-sink.properties > /opt/kafka/kafka-mongo-info.out 2> /opt/kafka/kafka-mongo-error.err &'

while true
do

# nohup $ex 1> nohup_kms.out 2> nohup_kms.err | tee -a /var/log/my_uber_script.log
# nohup $ex 1> nohup_kms.out 2> nohup_kms.err

done

you can try any one inside the loop

Not able to start 2 tasks using Dockerfile CMD

One process inside docker container has to run not in background mode, because docker container is running while main process inside it is running.

The /scripts/entryPoint.sh should be:

#!/bin/bash
nohup /bin/bash -c "http-server -p 80 /ui" &
nohup /bin/bash -c "mb --port 2525 --configfile /mb/imposters.ejs --allowInjection"

Everything else is fine in your Dockerfile.

Commands to execute background process in Docker CMD

Besides the comments on your question that already pointed out a few things about Docker best practices you could anyway start a background process from within your start.sh script and keep that start.sh script itself in foreground using the nohup command and the ampersand (&). I did not try it with mongod but something like the following in your start.sh script could work:

#!/bin/sh
...
nohup sh -c mongod --dbpath /test &
...


Related Topics



Leave a reply



Submit