Docker container application Service self-boot __tomcat

Source: Internet
Author: User
Tags docker run
Docker container application Service self-starter

If you want the application service within the Docker container to start as the container opens. Just write the service startup script in the Dockerfile, and then use Dockerfile to refactor the mirror to do it: write the application service from the startup script dockerfile reconstruct the mirror to open the container writing Service self-starter scripts (Dockerd)

(Tomcat for example)

#!/bin/bash # # # # # chkconfig:345 Description:tomcat program.
# processname:tomcat # Source function library. .
/etc/rc.d/init.d/functions # Source Networking configuration. #. /etc/sysconfig/network prog= "Tomcat" checkprocess () {chkret= ' ps-ef |grep $prog |grep-v ' grep ' |wc-l ' re

Turn $chkret} start () {cd/usr/local/tomcat/bin/./startup.sh echo "Service $prog started!"} #/usr/sbin/nscd &/usr/sbin/sshd-d & While [true] do dnsip=172.18.3.179 pi
                        Ng= ' ping-c 3 $DNSIP |awk ' nr==7 {print $} ' if [[$ping-eq ' 3]] Then Break fi 3 did while [true] do checkprocess if [[$chkret-eq] 
                    0 "]] then start #nscd-I hosts Else

                echo "Service $prog is running." Fi sleep done exIt 0 
Write Dockerfile
From  Tomcat


maintainer Liu "350142639@qq.com"



ADD dockerd  /etc/rc.d/init.d/
RUN chmod 777  / Etc/rc.d/init.d/dockerd

env java_home  /usr/local/jdk1.6.0_30
env PATH      $JAVA _home/bin: $PATH
ENV CLASSPATH   .: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar




Cmd/etc/rc.d/init.d/dockerd

Where add the script in the sibling directory to the specified location in the mirror, ENV set the Java environment variable (it is important not to write this since the startup script cannot perform successfully) The CMD command can only have one to execute the command when the container is started. It can also be a script. Refactoring Mirrors

* * Through
Docker build-t the new mirror name.
Successful creation of a new mirror opening container

Docker run-d-h= "s" –name= "s" New mirror Name

Then, find that Tomcat is turned on,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.