How to keep running after exiting Docker container

How to keep running after exiting Docker container

Phenomenon:

Run an image, for example, ubuntu14.04:

docker run -it --rm ubuntu:14.04 bash

On exit:

Execute Ctrl+D or execute exit

View the thread:

docker ps

It is empty, indicating that there is no running container.

Solution:

Run an image:

docker run -dit ubuntu:14.04

View the thread:

Found a thread and opened it:

docker attach 【CONTAINER ID or NAMES】

If you want to continue running when exiting: press [ctrl+p], [ctrl+q] in sequence

If you do not want to continue running: press [ctrl+d] or enter exit

In addition: To restart after shutdown, please enter: docker restart [CONTAINER ID or NAMES]

Supplement: Docker - Avoid running a shell script after starting the container and then exiting the container after the execution is completed

Recently, I was using Dockerfile to start a container and found that when I used Dockerfile to call the shell in the container, Docker would exit the container after the shell was executed.

analyze

When Docker executes the shell, it executes it in the background; therefore, after the shell is executed, Docker detects that there is no foreground task to be executed and exits the container.

Workaround

Add a "never complete" command to the end of the shell script:

# tail -f /dev/null

In this way, when this command is executed, the shell will not exit, and the container will not exit either.

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:
  • Talk about the issue of replacing docker (shim) with containerd in kubernetes1.20
  • Docker removes abnormal container operations
  • Goodbye Docker: How to Transform to Containerd in 5 Minutes
  • Docker dynamically exposes ports to containers
  • Delete the image operation of none in docker images
  • Implementation of local migration of docker images
  • Solve the problem of docker images disappearing
  • Docker image cannot be deleted Error: No such image: xxxxxx solution
  • How to delete an image in Docker
  • Naming containers and images in Docker

<<:  A collection of button hover border and background animations based on CSS properties

>>:  How to redirect PC address to mobile address in Vue

Recommend

The difference between char, varchar and text field types in MySQL

In MySQL, fields of char, varchar, and text types...

Example of how to exit the loop in Array.forEach in js

Table of contents forEach() Method How to jump ou...

JavaScript event capture bubbling and capture details

Table of contents 1. Event Flow 1. Concept 2. DOM...

Teach you to create custom hooks in react

1. What are custom hooks Logic reuse Simply put, ...

How to make React components full screen

introduce This article is based on React + antd t...

What are inline elements and block elements?

1. Inline elements only occupy the width of the co...

HTML code example: detailed explanation of hyperlinks

Hyperlinks are the most frequently used HTML elem...

MySQL 8.0.22.0 download, installation and configuration method graphic tutorial

MySQL 8.0.22 download, installation and configura...

Implementation code of short video (douyin) watermark removal tool

Table of contents 1. Get the first link first 2. ...

Implementation of k8s node rejoining the master cluster

1. Delete node Execute kubectl delete node node01...

How to use shell to perform batch operations on multiple servers

Table of contents SSH protocol SSH Connection pro...

Summary of the understanding of virtual DOM in Vue

It is essentially a common js object used to desc...

Detailed explanation and summary of the URL for database connection

Detailed explanation and summary of the URL for d...

Docker container time zone error issue

Table of contents background question Problem ana...