Today I encountered a problem when I used Dockerfile to create an image, and the container ended automatically after the image was run. Start command:
After running, use docker ps to find that the docker container has ended After searching for information, I found that this problem is not complicated. The reason is that when the Docker container runs in the background, there must be a foreground process. Solution: 1. Start the running process in the foreground, such as: nginx nginx -g "daemon off;" tomcat ./catalina.sh run 2. Use tail, top, and other programs that can run in the foreground. Tail is especially recommended to output your log file. Add ENTRYPOINT /opt/tomcat7.0/bin/startup.sh && tail -F /opt/tomcat7.0/logs/catalina.out to Dockerfile Additional knowledge: The tomcat pulled by docker pull did not generate logs, so I wrote a tocmat dockerfile file by hand, and it was tested that logs were generated 1. The dockfile file and its explanation are as follows FROM openjdk:8-jre MAINTAINER ENV JAVA_HOME /docker-java-home ENV CATALINA_HOME /opt/tomcat ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:$CATALINA_HOME/scripts #Timezone RUN echo "Asia/Shanghai" > /etc/timezone RUN mv /etc/localtime /etc/localtime_bak RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #TOMCAT ENV TOMCAT_MAJOR 8 ENV TOMCAT_VERSION 8.5.35 RUN wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.41/bin/apache-tomcat-8.5.41.tar.gz && \ tar -zxvf apache-tomcat-8.5.41.tar.gz && \ rm apache-tomcat*.tar.gz && \ mv apache-tomcat* ${CATALINA_HOME} RUN chmod +x ${CATALINA_HOME}/bin/*sh RUN chmod 777 ${CATALINA_HOME}/logs/ RUN chmod 777 ${CATALINA_HOME}/webapps/ #Set username and password to admin ADD tomcat-users.xml /opt/tomcat/conf/ #Remote access ADD context.xml /opt/tomcat/webapps/manager/META-INF/ ENV LANG zh_CN.UTF-8 #Open port EXPOSE 8080 # Launch Tomcat WORKDIR /opt/tomcat/bin CMD ["catalina.sh","run"] Note: This docker needs to reference external files See github for details 2. Dockerfile compilation command
3. Run Command docker run -d -p 8080:8080 --name tomcat8 -v /opt/docker-tomcat/logs/:/opt/tomcat/logs/ -v /opt/docker-tomcat/webapps/:/opt/tomcat/webapps/ -v /opt/docker-tomcat/context.xml:/opt/tomcat/webapps/manager/META-INF/context.xml -v /opt/docker-tomcat/tomcat-users.xml:/opt/tomcat/conf/tomcat-users.xml --privileged=true zyj/tomcat The above solution to the problem that docker run container automatically ends is all I have to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of two points to note in vue3: setup
>>: MySQL json format data query operation
Definition of Float Sets the element out of the n...
The complete syntax of the SELECT statement is: (...
The ogg process of a database produced some time ...
<input> is used to collect user information ...
This article mainly introduces the analysis of th...
1. Problem Description When starting MYSQL, a pro...
After setting the table width in the page to width...
This article example shares the specific code of ...
Text Shadow text-shadow: horizontal offset vertic...
What is volume? Volume means capacity in English,...
I recently used Dreamweaver to make a product pres...
background When developing a feature similar to c...
Docker Compose is a Docker tool for defining and ...
Copy code The code is as follows: <!--doctype ...
HTML-centric front-end development is almost what ...