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?

  • Docker - Cassandra
  • Building Docker Images with
  • How can I use dynamic linking in a Docker image based on busybox?
  • How to get stdin from php for java docker container at runtime
  • Ping work but Java code fails with host is unreachable in Docker
  • Gitlab CI build failed with “Preparation failed: cannot connect to Docker endpoint”
  • 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?

  • How to check the configuration of Docker (volume, devicemapper, ..) after deleting many files ?
  • How to escape Fish shell variable to use as awk pattern?
  • How to use the rabbitmq docker compose yml file to build docker image?
  • Starting a docker container with a node.js app produces error; complains about PATH
  • Docker creates huge image sizes
  • getting meteor do work in docker + commiting and then rerunning issue
  • 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.