Docker removes abnormal container operations

Docker removes abnormal container operations

This rookie encountered such a problem when he just started learning Docker. Let me record it.

When starting a container, docker ps shows that there is a problem with the newly started container.

Then docker logs <container id> realized that the permissions were insufficient and the directory could not be created. Then I wanted to start it, but the current container was always restarting. I tried docker stop and it returned success. Then docker ps showed that the current container still existed. Then when I tried docker kill, it said that the container was not started. I checked it with docker -help and removed the container with docker rm.

However, this command cannot remove a container in the restarting state.

You need to docker stop <container id> first and then docker rm it.

Of course, the startup failed because of lack of permission. The docker container does not have permission to add the --privileged=true parameter.

When running docker-compose, docker-compose up will give priority to using existing containers instead of recreating containers. You need to bring the --force-recreate parameter to recreate the container docker-compose up -d --force-recreate

I am a docker novice, so I will record the problems I encountered. Please don't criticize me.

Supplement: Docker deletes a large number of stopped containers

1. How to do it

The official recommendation is to use docker rm $(sudo docker ps -a -q) to delete and stop containers in batches.

Do not use docker rm -f $(sudo docker ps -a -q), it will delete all containers

2. Why do you do this?

1. docker ps -a -q

Explanation of the docker ps command:

docker ps -a -q lists the numeric IDs of all containers
root@haha:~# docker ps --help
Usage: docker ps [OPTIONS]
List containers
Options:
 -a, --all Show all containers (default shows just running)
 -f, --filter value Filter output based on conditions provided (default [])
   --format string Pretty-print containers using a Go template
   --help Print usage
 -n, --last int Show n last created containers (includes all states) (default -1)
 -l, --latest Show the latest created container (includes all states)
   --no-trunc Don't truncate output
 -q, --quiet Only display numeric IDs
 -s, --size Display total file sizes

Specifically, docker ps is the command to list containers

-a lists all containers -q shows only numeric IDs

2. Explanation of the docker rm command:

root@haha:~# docker rm --help
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
Remove one or more containers
Options:
 -f, --force Force the removal of a running container (uses SIGKILL)
   --help Print usage
 -l, --link Remove the specified link
 -v, --volumes Remove the volumes associated with the container

-f Force deletion, you can delete the running container

-v After the container is started, the data will exist in the form of volumes on the hard disk. Even if the container data is deleted, it will not be deleted. If this parameter is added, the data executed by the container will also be deleted.

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
  • How to keep running after exiting Docker container
  • 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

<<:  How to recover data after accidentally deleting ibdata files in mysql5.7.33

>>:  Learn how to write neat and standard HTML tags

Recommend

MySql inserts data successfully but reports [Err] 1055 error solution

1. Question: I have been doing insert operations ...

Implementing a web calculator with native JavaScript

This article shares the specific code of JavaScri...

...

Common browser compatibility issues (summary)

Browser compatibility is nothing more than style ...

The best 9 foreign free picture material websites

It is difficult to find good image material websi...

JS Decorator Pattern and TypeScript Decorators

Table of contents Introduction to the Decorator P...

Detailed explanation of the use of grid properties in CSS

Grid layout Attributes added to the parent elemen...

Nginx cache configuration example

When developing and debugging a web application, ...

HTML input file control limits the type of uploaded files

Add an input file HTML control to the web page: &...

Introduction to the use of MySQL official performance testing tool mysqlslap

Table of contents Introduction Instructions Actua...

Complete steps to build a Laravel development environment using Docker

Preface In this article, we will use Docker to bu...

Using react-beautiful-dnd to implement drag and drop between lists

Table of contents Why choose react-beautiful-dnd ...