Solve the problem of docker container exiting immediately after starting

Solve the problem of docker container exiting immediately after starting

Recently I was looking at how Docker allows containers to directly run certain processes when they start, and later I found that Dockerfile can specify the container running command when the container starts.

CMD specifies, but each Dockerfile can only have one CMD instruction. If multiple CMD instructions are specified, only the last one will be executed.

So I thought of a way, wrote a script, started multiple processes in the script, and ran the script in Dockerfile.

Finally, this method was proved to be feasible. However, a problem was encountered during the experiment. The container stopped immediately after starting.

After consulting the information:

A Docker container can only manage one process at a time. If this process exits, the container will also exit. However, this does not mean that the container can only run one process (other processes can run in the background). However, in order for the container to not exit, there must be a process executing in the foreground.

Solution:

The last process in the script must be run in foreground mode, that is, do not add & (& means background running) at the end of the process, otherwise the container will exit.

Supplementary knowledge: Problems and solutions when using gdbserver in a docker container

I have a problem when using gdbserver in a docker container

linux_ptrace_test_ret_to_nx: Cannot PTRACE_TRACEME:operation not permmit

The reason is that Docker disables the PTRACE function by default and needs to be enabled when the container is running.

docker run -ti --cap-add=SYS_PTRACE ubuntu

The above article on solving the problem of docker container exiting immediately after starting is all the content that the editor shares with you. I hope it can give you a reference, and I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Each time Docker starts a container, the IP and hosts specified operations
  • Detailed explanation of Shell script control docker container startup order
  • Docker modifies the configuration information of an unstarted container
  • Dockerfile implementation code when starting two processes in a docker container
  • Docker file storage path, get container startup command operation
  • Docker batch start and close all containers

<<:  Document Object Model (DOM) in JavaScript

>>:  Introduction to HTML DOM_PowerNode Java Academy

Recommend

MySQL 8.0.20 installation tutorial and detailed tutorial on installation issues

Original address: https://blog.csdn.net/m0_465798...

Detailed explanation of using pt-heartbeat to monitor MySQL replication delay

pt-heartbeat When the database is replicated betw...

Tudou.com front-end overview

1. Division of labor and process <br />At T...

Detailed steps to install Nginx on Linux

1. Nginx installation steps 1.1 Official website ...

HTML tag overflow processing application

Use CSS to modify scroll bars 1. Overflow setting...

Login interface implemented by html+css3

Achieve results First use HTML to build a basic f...

Implementation of tomcat deployment project and integration with IDEA

Table of contents 3 ways to deploy projects with ...

How to build nfs service in ubuntu16.04

Introduction to NFS NFS (Network File System) is ...

Why Google and Facebook don't use Docker

The reason for writing this article is that I wan...

Linux uses iftop to monitor network card traffic in real time

Linux uses iftop to monitor the traffic of the ne...

Explanation of the new feature of Hadoop 2.X, the recycle bin function

By turning on the Recycle Bin function, you can r...