After docker run, the status is always Exited

After docker run, the status is always Exited

add -it

docker run -it -name test -d nginx:latest /bin/bash

-d: Run the container in the background and return the container ID;

-i: Run the container in interactive mode, usually used with -t;

-t: reallocate a pseudo input terminal for the container, usually used together with -i;

Additional knowledge: docker-compose starts nginx through sh command and the container automatically exits with code 0

In the template file used by docker-compose, the container is started automatically by executing the sh command through the entrypoint or command parameter to start the nginx service, but the container automatically exits after docker-compose up

nginx-web1 exited with code 0

nginx-web2 exited with code 0

nginx-web3 exited with code 0

Reason: Docker's mechanism is to run the container in the background. There must be at least one foreground process. If the command run by the container is not a command that has been suspended (such as running top, tail), it will automatically exit.

Solution: You can use the sh command containing the -g "daemon off;" configuration item to start the nginx service in the foreground mode.

nginx -c /usr/local/nginx/conf/nginx.conf -g "daemon off;"

If the container needs to start multiple processes at the same time, just suspend one of them to the foreground, for example:

service php-fpm start && nginx -g "daemon off;"

or

service php-fpm start && service nginx start && tail -f /var/log/nginx/error.log

The above article "The status is always Exited after docker run" is all the content that the editor shared 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 starts in Exited state
  • 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
  • Implementation of Docker container state conversion
  • Zabbix monitors docker container status [recommended]
  • How to monitor the running status of docker container shell script

<<:  Solve the problem that MySQL read-write separation causes data not to be selected after insert

>>:  Solve the mobile terminal jump problem (CSS transition, target pseudo-class)

Recommend

Share 13 excellent web wireframe design and production tools

When you start working on a project, it’s importa...

Detailed tutorial on installing Mysql5.7.19 on Centos7 under Linux

1. Download MySQL URL: https://dev.mysql.com/down...

A detailed introduction to the netstat command in Linux

Table of contents 1. Introduction 2. Output Infor...

js to make a simple calculator

This article shares the specific code of making a...

Detailed explanation of various HTTP return status codes

When a request is sent to your server to display ...

Implementation of multiple instances of tomcat on a single machine

1. Introduction First of all, we need to answer a...

Two ways to achieve horizontal arrangement of ul and li using CSS

Because li is a block-level element and occupies ...

How to use JavaScript strategy pattern to validate forms

Table of contents Overview Form validation withou...

Solution to JS out-of-precision number problem

The most understandable explanation of the accura...

Vue implements video upload function

This article example shares the specific code of ...

How to view image information in Docker

In this article, we will need to learn how to vie...

Summary of common tool functions necessary for front-end development

1. Time formatting and other methods It is recomm...

Summary of MySQL5 green version installation under Windows (recommended)

1 Download MySQL Download address: http://downloa...