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,