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

How to run multiple MySQL instances in Windows

Preface In Windows, you can start multiple MySQL ...

How to install Django in a virtual environment under Ubuntu

Perform the following operations in the Ubuntu co...

Detailed explanation of upgrading Python and installing pip under Linux

Linux version upgrade: 1. First, confirm that the...

MySQL merges multiple rows of data based on the group_concat() function

A very useful function group_concat(), the manual...

Detailed explanation of Linux copy and paste in VMware virtual machine

1. Linux under VMware Workstation: 1. Update sour...

MySQL 8.0.23 installation super detailed tutorial

Table of contents Preface 1. Download MySQL from ...

Solution to the problem of MySQL deleting and inserting data very slowly

When a company developer executes an insert state...

Web Design Tutorial (4): About Materials and Expressions

<br />Previous Web Design Tutorial: Web Desi...

Implementation of waterfall layout + dynamic rendering

Table of contents Typical waterfall website Water...

How to deploy services in Windows Server 2016 (Graphic Tutorial)

introduction Sometimes, if there are a large numb...

Detailed explanation of the available environment variables in Docker Compose

Several parts of Compose deal with environment va...

Detailed explanation of zabbix executing scripts or instructions on remote hosts

Scenario Requirements 1. We can use the script fu...