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

Two methods of MySql comma concatenation string query

The following two functions are used in the same ...

How to convert JavaScript array into tree structure

1. Demand The backend provides such data for the ...

JavaScript timer to achieve seamless scrolling of pictures

This article shares the specific code of JavaScri...

Some common advanced SQL statements in MySQL

MySQL Advanced SQL Statements use kgc; create tab...

Detailed explanation of transaction isolation levels in MySql study notes

background When we talk about transactions, every...

The difference between br and br/ in HTML

answer from stackflow: Simply <br> is suffic...

Implementation of running SQL Server using Docker

Now .net core is cross-platform, and everyone is ...

How to change the encoding to utf-8 in mysql version 5.7 under windows

Preface I just started learning MySQL and downloa...

MySQL sql_mode analysis and setting explanation

When inserting a set of data into the MySQL datab...

Solution to nginx not jumping to the upstream address

Preface Today I encountered a very strange proble...

JS implements random roll call system

Use JS to implement a random roll call system for...

Two ways to implement text stroke in CSS3 (summary)

question Recently I encountered a requirement to ...

Implementation of the Pycharm installation tutorial on Ubuntu 18.04

Method 1: Download Pycharm and install Download a...

Examples of correct judgment methods for data types in JS

Table of contents Preface Can typeof correctly de...