This is a creation in Article, where the information may have evolved or changed.
Some best practices in Docker usage
This article will record:
- Best practices that are organized in the process of using Docker.
- Other Docker user-published (possibly translated, all with original links) validated best practices.
Therefore, this article will be updated for a long time.
Docker Installation Related
If you use Docker after the installation is complete, the following error occurs:
> Cannot connect to the Docker daemon. Is 'docker -d' running on this host?
Referring to the content here, we need to execute the following command to install AppArmor:
sudo apt-get install apparmor
Docker Usage Related
- Using Bash Aliases to simplify Docker use commands, inspired by a great article (the site that publishes this article docker.cn is also a good Docker resource station), I've expanded:
Add the following content to the $HOME/.bash_aliases:
# Show all available docker related aliases.aliasdockeraliases=' printf ' \nbelow is all pre-defined docker maintainance Aliases:\n\ndkka | Dockerkillall\tkill All running Containers\ndksa | Dockerstopall\tstop All running CONTAINERS\NDKRC | Dockerremovec\tremove All stopped Containers\ndkri | Dockerremovei\tremove All untagged Images\ndkra | Dockerremovea\tremove all stopped containers and untagged images\n\n "'aliasDkas=' printf ' \nbelow is all pre-defined docker maintainance Aliases:\n\ndkka | Dockerkillall\tkill All running Containers\ndksa | Dockerstopall\tstop All running CONTAINERS\NDKRC | Dockerremovec\tremove All stopped Containers\ndkri | Dockerremovei\tremove All untagged Images\ndkra | Dockerremovea\tremove all stopped containers and untagged images\n\n "' # Kill all running containers.aliasDockerkillall=' printf ' \n>>> killing all running containers\n\n "&& Docker Kill $ (Docker ps-q) && printf" \ n "'aliasDkka=' printf ' \n>>> killing all running containers\n\n "&& Docker Kill $ (Docker ps-q) && printf" \ n "' # Stop all running containers.aliasDockerstopall=' printf ' \n>>> stopping all running containers\n\n "&& Docker stop $ (Docker ps-q) && printf "\ n" 'aliasDksa=' printf ' \n>>> stopping all running containers\n\n "&& Docker stop $ (Docker ps-q) && printf "\ n" ' # Remove all stopped containers.aliasDockerremovec=' printf ' \n>>> removing stopped containers\n\n "&& Docker RM $ (Docker ps-a-Q) && printf" \ n "'aliasDKRC=' printf ' \n>>> removing stopped containers\n\n "&& Docker RM $ (Docker ps-a-Q) && printf" \ n "' # Remove all untagged images.aliasDockerremovei=' printf ' \n>>> removing untagged images\n\n ' && Docker RMI $ (Docker images-q-F dangling=true) & & printf "\ n" 'aliasDkri=' printf ' \n>>> removing untagged images\n\n ' && Docker RMI $ (Docker images-q-F dangling=true) & & printf "\ n" ' # Remove All stopped containers and untagged images.aliasDockerremovea=' Dockerremovec | | true && dockerremovei 'aliasDkra=' Dockerremovec | | true && dockerremovei '
You can then use these aliases by executing "source ~/.bash_aliases" on the command line, such as:
$ dkasBelow are all pre-defined docker maintainance aliases:dkka | dockerkillall Kill all running containersdksa | dockerstopall Stop all running containersdkrc | dockerremovec Remove all stopped containersdkri | dockerremovei Remove all untagged imagesdkra | dockerremovea Remove all stopped containers and untagged images
--EOF--
- Climbing stairs and Fibonacci series →
- ←ubuntu 14.04 based on the latest OpenSSL compiler curl
Disclaimer: This article uses the BY-NC-SA protocol to authorize. Reprint please specify transfer from: Some best practices in Docker usage