How to keep a service running on a Docker container

I am trying to run a simple docker container with my web application installed (Not using docker file).
During the testing I would always run a container using -t -i option and then start the tomcat service inside it by running a shell script.
How when I am moving to production I dont want to use the -t -i option any more and just need my Tomcat service to start and be the only primary service.

I trying pointing the entrypoint to the start up script for starting tomcat but the container terminates after that script finishes.
How do I run a container, start a service and keep that service as the single primary service of the container?

  • TravisCI/Docker: parameterized start of docker containers with matrix feature
  • Running Jenkins in a Docker Container
  • Attaching process to Docker libcontainer container
  • How can I use gitlab and/or docker for my web app?
  • gunicorn with flask application not allowing more than one connection
  • Docker OnlyOffice - Nginx 111 Error
  • Note: I read some posts about supervisor but not sure if I would need to start building my image from scratch if I go that route? I would prefer not doing that.

    Any suggestions?

  • Artifactory docker Repository overrides released docker artifacts
  • docker-compose image export and import
  • How to fix output from tty of Docker for macOS vm?
  • Docker tomcat7 container cannot connect to host activemq
  • Auto-synch data in container upon changes in host
  • What is the special gitlab-ci-token user?
  • 3 Solutions collect form web for “How to keep a service running on a Docker container”

    If you have a Dockerfile that uses an entrypoint pattern, it will look something like this:


    FROM ubuntu
    ...Some configuration steps...
    add /
    ENTRYPOINT ["/"]

    All you need to do is make sure your script ‘hangs’ in some way. Some people like to tail the syslogs, but tailing any file that exists will work.


    service Your_Service_Or_Whatever start
    tail -f /var/log/dmesg

    Docker containers as default will run according to the configuration in the images Dockerfile. If you usually run a container with the -i flag, you leave STDIN open allowing you access to the containers entrypoint or it could be a bash shell. To achieve what you want, you can run the container in a detached state passing your commands into docker run directly.

    docker run -d myapp /opt/catalina/bin/

    This will run the myapp container in a detached state and will run the command passed as the 3rd argument. If the command results in a long lived service, the container will stay active as long as the service is.

    This is explained in detail in the docs.

    A shorter version:

    FROM ubuntu
    ...Some configuration steps...
    ENTRYPOINT ["/bin/sh", "-c", "while true; do sleep 1; done"]

    tested with Docker version 1.12.1, build 23cf638

    Use docker --version to find out your version

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.