Solve the problem of the container showing Exited (0) after docker run

Solve the problem of the container showing Exited (0) after docker run

I made a Dockerfile for openresty on centos7 and built it.

docker run -d -p 801:80 openresty:1.19 /usr/local/openresty/nginx/sbin/nginx

After that, docker ps -a shows the following

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9dee2d04b3b5 openresty:1.19 "/usr/local/openrest…" 24 seconds ago Exited (0) 7 seconds ago gifted_bhabha 69846af3baa7 redis:latest "docker-entrypoint.s…" 24 minutes ago Up 24 minutes 0.0.0.0:6379->6379/tcp rds

The openresty status is displayed as Exited (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.

solve:

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

Therefore, the startup command is adjusted as follows:

docker run -d -p 801:80 openresty:1.19 /usr/local/openresty/nginx/sbin/nginx -g "daemon off;"

Run docker ps -a again to see the effect

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0291303ca61b openresty:1.19 "/usr/local/openrest…" 29 seconds ago Up 28 seconds strange_curie 69846af3baa7 redis:latest "docker-entrypoint.s…" 26 minutes ago Up 26 minutes 0.0.0.0:6379->6379/tcp rds

Supplement: Docker is always in the exited state when it is started. Solution

Docker is always in the exited state when it is started

Workaround

Step 1. Docker rm container id to delete the container

Step 2: docker rmi image id to delete the image (the image can only be deleted after deleting the container first)

Step 3: docker build -t tomcat:centos . Recreate the container

Step 4. docker run --privileged -it -d --name tomcat01 -p 1216:8080 tomcat:centos (add permissions and)

Specify a pseudo terminal)

Cause of error 1. Lack of permissions 2. No terminal is running

Note: –privileged adds permissions

-t specifies a pseudo terminal

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • A time-consuming troubleshooting process record of a docker error
  • Docker Cannot connect to the Docker daemon. Is the docker daemon running on this host error solution
  • Docker daemon cannot start: does not match with stored UUID error solution
  • Solution for multiple Docker containers not having the same port number
  • Steps for docker container exit error code

<<:  Example code for circular hover effect using CSS Transitions

>>:  Implementation of mysql using mysqlbinlog command to restore accidentally deleted data

Recommend

Display special symbols in HTML (with special character correspondence table)

Problem Reproduction When using HTML for editing,...

Example code for using @media in CSS3 to achieve web page adaptation

Nowadays, the screen resolution of computer monit...

How to clean up Alibaba Cloud MySQL space

Today I received a disk warning notification from...

What does href=# mean in a link?

Links to the current page. ------------------- Com...

Analysis of the pros and cons of fixed, fluid, and flexible web page layouts

There is a question that has troubled web designe...

Two methods of implementing automatic paging in Vue page printing

This article example shares the specific code of ...

Several methods of implementing two fixed columns and one adaptive column in CSS

This article introduces several methods of implem...

How to use Docker plugin to remotely deploy projects to cloud servers in IDEA

1. Open port 2375 Edit docker.service vim /lib/sy...

Web Design: The Accurate Location and Use of Massive Materials

Three times of memorization allows you to remembe...

Three ways to communicate between React components (simple and easy to use)

Table of contents 1. Parent-child component commu...

Sharing of SVN service backup operation steps

SVN service backup steps 1. Prepare the source se...

Detailed explanation of how to create an array in JavaScript

Table of contents Creating Arrays in JavaScript U...

How to use ElementUI pagination component Pagination in Vue

The use of ElementUI paging component Pagination ...