Get the App
SLTechnology News&Howtos  ›  Servers  › 

What are the common operations of Docker containers?

Shulou Source: shulou.com Published: 2022-06-01 00:50:36 10月03日 Update

This article introduces you what the common operation of Docker container is, the content is very detailed, interested friends can use it for reference, hope to be helpful to you.

Learn about other common operations of containers here.

Stop/start/restart container

A container that can be stopped through docker stop.

The container is actually a process in docker host, and the docker stop command essentially sends a SIGTERM signal to that process. If you want to stop the container quickly, you can use the docker kill command, which sends a SIGKILL signal to the container process.

Containers that are in a stopped state can be restarted through docker start.

Docker start retains all the parameters from the first startup of the container.

Docker restart can restart the container, and its purpose is to execute docker stop and docker start in turn.

The container may stop running due to some error. For service containers, we usually want the container to restart automatically in this case. This can be achieved by setting-- restart when you start the container.

-- restart=always means that no matter why the container exits (including normal exit), it restarts immediately. This parameter can also be in the form of-- restart=on-failure:3, which means that if the startup process exit code is not 0, restart the container up to 3 times.

Pause/unpause container

Sometimes we just want to suspend the container for a while, such as taking a snapshot of the container's file system, or when dcoker host needs to use CPU, we can execute docker pause.

Containers in a paused state do not consume CPU resources until operation is resumed through docker unpause.

Delete Container

After using docker for a while, there may be a large number of exited containers on the host.

These containers will still consume the file system resources of host. If you confirm that such containers will not be restarted, you can delete them through docker rm.

Docker rm can specify multiple containers at a time. If you want to delete all exited containers in batch, you can execute the following command:

Docker rm-v $(docker ps-aq-f status=exited)

By the way: docker rm is to delete the container, while docker rmi is to delete the image.

So much for sharing about the common operations of Docker containers. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.

Tags: Containers processes commonly used commands runs functions signals contents parameters can be passed files time more status systems resources help good code interests Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology NVidia Redmi Xiaomi