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”,”start.sh”]

  • How to write a long command within dockerfile?
  • Get and pass into container the host IP address
  • How to setting Core file size in Docker container?
  • Docker with Java: path RUN javac
  • Using remote byebug instance with docker-compose
  • How is “lxd” different from lxc/docker?
  • I would like to execute a shell command with a process running in background example

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

  • How to dockerize a node.js talking to a local mongodb
  • Tell difference of a scaled app on Mesos
  • Cannot keep the scala application up and running on docker
  • Elasticsearch won't run with Docker
  • AngularJS on nginx in Docker container
  • What is the step by step process to deploy a java app to Docker?
  • 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 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 &
    ...
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.