Commands to execute background process in Docker CMD

I am creating a docker image using a Dockerfile. I would like to execute some scripts while starting the docker container. Currently I have a shell script to execute all the necessary processes

CMD [“sh”,””]

  • Connecting to RDS Mysql from docker container with WordPress
  • How to get client IP from request inside haproxy docker container?
  • Difference between nodejs v0.12 and v5.x distributions
  • How to quickly show policies of all docker containers
  • Docker how to create container
  • Docker: How to store images and metadata on another filesystem?
  • I would like to execute a shell command with a process running in background example

    CMD [“sh”, “-c”, “mongod –dbpath /test &”]

  • Can't deploy .war file using tomcat 6.0.24 and docker
  • ORA-31113 error when starting Apex 5 in Oracle 12c docker image
  • Why can't I run a simple ping from the IBM Liberty Docker image
  • edited files at host, but docker container is not refreshed
  • How to set the command history in a Dockerfile
  • How to ensure that web app in a container successfully bound to a port?
  • One Solution collect form web for “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 script and keep that 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 script could work:

    nohup sh -c mongod --dbpath /test &
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.