Unable to run Tomcat 7 as service inside container on CoreOS

I am trying to setup tomcat 7 on Digital Ocean CoreOS machine but facing some problem, not sure how to solve them. I am following below tutorial provided by the Digital Ocean to setup Apache.

https://www.digitalocean.com/community/tutorials/how-to-create-and-run-a-service-on-a-coreos-cluster

  • Docker Swarm Service - force update of latest image already running
  • How to expose a Docker network to the host machine?
  • Talking to remote docker from Linux to Windows
  • Environment variable in Docker
  • gitlab-ci-runner choose executer “Please enter the executor:”
  • Create shared package cache folder for a Docker container
  • I created docker container and run it using following command.

    docker run -i -t ubuntu:14.04 /bin/bash
    

    I was successfully able to install tomcat 7 by using below commands. (I followed this tutorial to setup tomcat 7 within the docker container: https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-7-on-ubuntu-14-04-via-apt-get)

    sudo apt-get update 
    sudo apt-get install tomcat7
    

    Then I can created service unit file named as tomcat@.service

    [Unit] 
    Description=Tomcat 7 web server service 
    After=etcd.service After=docker.service     
    Requires=tomcat-discovery@%i.service
    
    [Service] 
    TimeoutStartSec=0 KillMode=none 
    EnvironmentFile=/etc/environment 
    ExecStartPre=-/usr/bin/docker kill tomcat%i 
    ExecStartPre=-/usr/bin/docker rm tomcat%i 
    ExecStartPre=/usr/bin/docker pull attacomsian/tomcat 
    ExecStart=/usr/bin/docker run –name tomcat%i -p ${COREOS_PUBLIC_IPV4}:%i:8080 attacomsian/tomcat `service tomcat7 start` -D FOREGROUND 
    ExecStop=/usr/bin/docker stop tomcat%i
    
    [X-Fleet]
    X-Conflicts=tomcat@*.service
    

    Then I created tomcat-discovery@.service to register service states with Etcd as below

    [Unit] 
    Description=Announce Tomcat@%i service 
    BindsTo=tomcat@%i.service
    
    [Service] 
    EnvironmentFile=/etc/environment
    ExecStart=/bin/sh -c “while true; do etcdctl set /announce/services/tomcat%i ${COREOS_PUBLIC_IPV4}:%i –ttl 60; sleep 45; done” 
    ExecStop=/usr/bin/etcdctl rm /announce/services/tomcat%i
    
    [X-Fleet]
    X-ConditionMachineOf=tomcat@%i.service
    

    I submitted and loaded files to Fleet as below

    fleetctl submit tomcat@.service tomcat-discovery@.service
    
    fleetctl load tomcat@8080.service
    
    fleetctl load tomcat-discovery@8080.service
    

    Everything worked fine so far. I did not see any error. But when I tried to run the service as below

    fleetctl start tomcat@8080.service
    

    But it did not started. I can see it is appearing as dead.

    I am new to CoreOS and still learning. I am managing servers at Digital Ocean and I quite about it quite well. I googled about this issue but did not found any help. I personally think following line is actually causing the trouble.

    ExecStart=/usr/bin/docker run –name tomcat%i -p ${COREOS_PUBLIC_IPV4}:%i:8080 attacomsian/tomcat `service tomcat7 start` -D FOREGROUND
    

    I would really appreciate any kind help to get this up.

    Many Thanks

    Attacomsian

  • Proper way to monitor PostgreSQL running inside a docker container
  • How do I attach to an existing docker-machine (Azure)?
  • How to connect to remote docker running on Ubuntu host
  • Node-inspector in docker container using docker-compose
  • Issue withDocker Selenium Grid on VM
  • How to port data-only volumes from one host to another?
  • One Solution collect form web for “Unable to run Tomcat 7 as service inside container on CoreOS”

    I was going so suggest you take a look at what others have done and then discovered you have posted a similar question on the Docker Hub registry.

    Did you take a look at the Docker file used by the tutum/tomcat image?

    It runs a script called “run.sh” that runs tomcat in the foreground.

    The thing that is tricky to understand is that Docker is not a virtual machine and therefore does not have any services running. You must run the docker processes explicitly or setup a process manager like runit or supervisord.

    Hope this helps.

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