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

Vue uses canvas to realize image compression upload

This article shares the specific code of Vue usin...

Docker runs operations with specified memory

as follows: -m, --memory Memory limit, the format...

Detailed explanation of MySql data type tutorial examples

Table of contents 1. Brief Overview 2. Detailed e...

vue+ts realizes the effect of element mouse drag

This article example shares the specific code of ...

Nginx content cache and common parameter configuration details

Use scenarios: The project's pages need to lo...

Linux 6 steps to change the default remote port number of ssh

The default ssh remote port in Linux is 22. Somet...

Best Practices for Deploying ELK7.3.0 Log Collection Service with Docker

Write at the beginning This article only covers E...

Add a floating prompt for the header icon in the ElementUI table

This article mainly introduces how to add floatin...

MySQL Optimization: InnoDB Optimization

Study plans are easily interrupted and difficult ...

Three examples of blur background effects using CSS3

Let’s not start with the introduction and get str...

How to monitor array changes in JavaScript

Preface When introducing defineProperty before, I...

WeChat applet implements form verification

WeChat applet form validation, for your reference...