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 Exec command does not work properly
  • How do docker containers resolve hostname of other docker containers running on the same machine?
  • Docker containers seem to 'inherit' the instance profile of the host ec2. How?
  • docker-py: client and server don't have same version (client : 1.16, server: 1.15)")
  • Wget numeric pattern in Dockerfile
  • How to connect to 'real' localhost from inside my VM boot2docker container?
  • 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?

  • Options -Indexes not working in .htaccess file in Docker continer
  • Can't create docker swarm service
  • Symfony app deployment with docker
  • Docker Issue -Image State not getting saved
  • Connecting go and postgres with docker-compose
  • List containers in the same docker-compose
  • 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.