docker run rm Option Instructions
- 2021-09-12 02:40:23
- OfStack
When the Docker container exits, the file system inside the default container is still preserved to facilitate debugging and preserve user data.
However, for foreground container, because it only runs for a short time in the development and debugging process, it is not necessary to keep its user data, so the-rm option can be set when the container starts, so that the file system inside the container can be automatically cleaned when the container exits.
Examples are as follows:
docker run --rm ba-208
Equivalent to
docker run --rm=true ba-208
Obviously, the--rm option can't be used with--d (or it doesn't make sense to use it at the same time), that is, only foreground containers can be cleaned automatically, but detached containers can't be cleaned automatically.
Note that the--rm option also cleans the container's anonymous data volumes.
Therefore, executing the docker run command with the--rm command option is equivalent to executing docker rm--v after the container exits.
Additional knowledge: Use the docker run--cap-add parameter to resolve permission issues (cannot debug with gdb, cannot modify time with date--s)
The problem is that centos in the docker container cannot be debugged using gdb
ptrace: Operation not permitted
Solution reference: Click to enter
Add the parameter to the docker run command--cap-add=SYS_PTRACE
docker run --cap-add=SYS_PTRACE ......
More cap can be found in the manual
http://man7.org/linux/man-pages/man7/capabilities.7.html
There is also a less elegant approach that is not recommended: solving privileged through privileged is equivalent to cap-add=ALL.
A similar problem is that date-s modification time cannot be used on docker machines
Solution:
docker run --cap-add=SYS_TIME --cap-add=SYS_PTRACE...