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
A colleague reported that a MySQL instance could ...
1. About Registry The official Docker hub is a go...
Preface Linux has corresponding open source tools...
Table of contents 1. The concept of closure Addit...
I want to make a page using CSS3 rounded corners ...
In a recent project, I needed to implement the fu...
Table of contents Preface 1. Arrange the installa...
Table of contents Quick Start How to use Core Pri...
Recently, when I was using C# to make a Web progra...
Table of contents 1. Background 2. Understanding ...
Table of contents 1. Definition of stack 2. JS st...
question Running gdb in docker, hitting a breakpo...
01. Command Overview The gcc command uses the C/C...
Preface In our daily work, we often need to renam...
1 Introduction Apache Storm is a free, open sourc...