Docker container exits after running (how to keep running)

Docker container exits after running (how to keep running)

Phenomenon

Start the Docker container

docker run –name [CONTAINER_NAME] [CONTAINER_ID]

Check the running status of the container

docker ps -a

It is found that the mydocker container just started has exited

reason

It is very important to point out that for a Docker container to run in the background, there must be a foreground process.

If the command run by the container is not a command that has been suspended (such as running top or tail), it will automatically exit.

The main thread of the docker container (the command executed by CMD in the dockerfile) ends and the container exits

Workaround

You can use interactive startup

docker run -i [CONTAINER_NAME or CONTAINER_ID]

The above is not very friendly, it is recommended to use background mode and tty options

docker run -dit [CONTAINER_NAME or CONTAINER_ID]

View container status

docker ps -a

Docker calls out the background container

docker attach [CONTAINER_NAME or CONTAINER_ID]

Tips: When exiting, use [ctrl + D], which will end the current Docker thread and the container. You can use [ctrl + P] [ctrl + Q] to exit without terminating the container.

The following command will execute the specified command in the specified container. [ctrl+D] will not terminate the container after exiting.

docker exec -it [CONTAINER_NAME or CONTAINER_ID] /bin/bash

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Example of how to create and run multiple MySQL containers in Docker
  • How does docker swarm run a specified container on a specified node?
  • How to remotely mount volumes when running Docker containers
  • Detailed explanation of running Spring Boot applications in Docker containers
  • Running nginx in a Docker container
  • Running a Java Web project built with MyEclipse in a Dockerfile container in Docker
  • Running Docker containers securely in production
  • Detailed explanation of how to mount the file system in a running Docker container
  • A brief analysis of the reasons why you don’t need to run sshd in a Docker container

<<:  A brief talk about React Router's history

>>:  Windows 10 and MySQL 5.5 installation and use without installation detailed tutorial (picture and text)

Recommend

HTML mouse css control

Generally speaking, the mouse is displayed as an u...

MySQL Installer 8.0.21 installation tutorial with pictures and text

1. Reason I just needed to reinstall MySQL on a n...

Vue's vue.$set() method source code case detailed explanation

In the process of using Vue to develop projects, ...

Bootstrap 3.0 study notes grid system principle

Through the brief introduction in the previous tw...

Vue implements an example of pulling down and scrolling to load data

Table of contents Step 1: Installation Step 2: Ci...

JS realizes the scrolling effect of announcement online

This article shares the specific code of JS to ac...

How to build YUM in Centos7 environment

1. Enter the configuration file of the yum source...

Teach you 10 ways to center horizontally and vertically in CSS (summary)

A must-have for interviews, you will definitely u...

Use overflow: hidden to disable page scrollbars

Copy code The code is as follows: html { overflow...

Vue custom bullet box effect (confirmation box, prompt box)

This article example shares the specific code of ...

Detailed explanation of various usages of proxy_pass in nginx

Table of contents Proxy forwarding rules The firs...

Three.js sample code for implementing dewdrop animation effect

Preface Hello everyone, this is the CSS wizard - ...

A summary of detailed insights on how to import CSS

The development history of CSS will not be introd...

Mysql SQL statement operation to add or modify primary key

Add table fields alter table table1 add transacto...