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

About CSS floating and canceling floating

Definition of Float Sets the element out of the n...

A brief understanding of MySQL SELECT execution order

The complete syntax of the SELECT statement is: (...

Using zabbix to monitor the ogg process (Linux platform)

The ogg process of a database produced some time ...

HTML simple web form creation example introduction

<input> is used to collect user information ...

Analysis of the Principle of MySQL Index Length Limit

This article mainly introduces the analysis of th...

How to solve the problem of ERROR 2003 (HY000) when starting mysql

1. Problem Description When starting MYSQL, a pro...

Set the width of the table to be fixed so that it does not change with the text

After setting the table width in the page to width...

js realizes the function of clicking to switch cards

This article example shares the specific code of ...

New settings for text and fonts in CSS3

Text Shadow text-shadow: horizontal offset vertic...

Implementation of sharing data between Docker Volume containers

What is volume? Volume means capacity in English,...

How to remove the blue box that appears when the image is used as a hyperlink

I recently used Dreamweaver to make a product pres...

MySql8 WITH RECURSIVE recursive query parent-child collection method

background When developing a feature similar to c...

Detailed installation and use of docker-compose

Docker Compose is a Docker tool for defining and ...

HTML is the central foundation for the development of WEB standards

HTML-centric front-end development is almost what ...