Docker clean up command highlights
- 2020-05-13 03:52:37
- OfStack
Kill all running containers
docker kill $(docker ps -a -q)
Delete all containers that have been stopped
docker rm $(docker ps -a -q)
Delete all images without the dangling tag
docker rmi $(docker images -q -f dangling=true)
Delete all images
docker rmi $(docker images -q)
Create aliases for these commands
# ~/.bash_aliases
Kill all running containers.
alias dockerkill='docker kill $(docker ps -a -q)'
Remove all containers that have been stopped.
alias dockercleanc='docker rm $(docker ps -a -q)'
Remove all untagged images.
alias dockercleani='docker rmi $(docker images -q -f dangling=true)'
Remove all stopped containers and untagged images.
alias dockerclean='dockercleanc || true && dockercleani'
Also attach the docker common command
docker version # view version
docker search tutorial# search is available with docker images
docker pull learn/tutorial # download image
docker run learn/tutorial echo "hello word"# run hello world in docker container!
docker run learn/tutorial apt-get install-y ping# install the new program in the container
Save the image
First use the docker ps-l command to get the id for the container after the ping command has been installed. Then save the image as learn/ping.
Tip:
1. Run docker commit to see the parameter list for this command.
2. You need to specify ID to submit the save container. (via the docker ps-l command)
3. You don't need a full copy of id. Usually the first 3 or 4 letters are distinguishable. (very similar to the version number in git)
Correct command:
docker commit 698 learn/ping
Run the new image
docker run lean/ping ping www.google.com
Check the running image
Now that you have one docker container running, let's look at the one that is running.
The docker ps command allows you to see a list of all the containers that are running, and the docker inspect command allows you to see more detailed information about a particular container.
Goal:
Find id for a running container, and use the docker inspect command to view the container's information.
Tip:
You can use the front part of the mirror id, not the full id.
Correct command:
docker inspect efe
ps is still in the development stage and is not recommended to be deployed to production environment.