Solution to the automatic termination of docker run container

Solution to the automatic termination of docker run container

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:

docker run -d -p 8080:8080 -v /usr/local/tomcat7.0/logs:/usr/local/tomcat7.0/logs --name tomcatweb tomcat:7.0

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

docker build -f dockerfile -t zyj/tomcat .

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:
  • docker run -v mounts data volumes abnormally, and the container status is always restarting
  • A brief discussion on the problem of Docker run container being in created state
  • What to do if the container started by docker run hangs and loses data
  • Docker Runc container life cycle detailed introduction
  • Solve the problem of the container showing Exited (0) after docker run

<<:  Detailed explanation of two points to note in vue3: setup

>>:  MySQL json format data query operation

Recommend

How to fix abnormal startup of mysql5.7.21

A colleague reported that a MySQL instance could ...

The implementation process of Linux process network traffic statistics

Preface Linux has corresponding open source tools...

JavaScript Advanced Closures Explained

Table of contents 1. The concept of closure Addit...

Let IE6, IE7, IE8 support CSS3 rounded corners and shadow styles

I want to make a page using CSS3 rounded corners ...

Implementation of breakpoint resume in vue-video-player

In a recent project, I needed to implement the fu...

MySQL graphical management tool Navicat installation steps

Table of contents Preface 1. Arrange the installa...

Vue3.x uses mitt.js for component communication

Table of contents Quick Start How to use Core Pri...

Use CSS to set the width of INPUT in TD

Recently, when I was using C# to make a Web progra...

Summary of MySQL composite indexes

Table of contents 1. Background 2. Understanding ...

Detailed explanation of JavaScript stack and copy

Table of contents 1. Definition of stack 2. JS st...

Specific use of Linux gcc command

01. Command Overview The gcc command uses the C/C...

How to Rename Multiple Files at Once in Linux

Preface In our daily work, we often need to renam...

Detailed process of compiling and installing Storm on Kylin V10 server

1 Introduction Apache Storm is a free, open sourc...