docker|docker常见命令

1.帮助命令 1.docker version #显示docker的版本信息
docker|docker常见命令
文章图片

2.docker info # 显示docker额系统信息,包括镜像和容器数量
docker|docker常见命令
文章图片

3. docker 命令 --help
官网文档地址
https://docs.docker.com/engine/reference/commandline/docker/
2.镜像命令 1.docker images
docker|docker常见命令
文章图片

REPOSITORY 镜像的仓库源 TAG镜像的标签 IMAGE ID镜像的id CREATED镜像的创建时间 SIZE镜像的大小Options: -a, --allShow all images (default hides intermediate images) --digestsShow digests -f, --filter filterFilter output based on conditions provided --format stringPretty-print images using a Go template --no-truncDon't truncate output -q, --quietOnly show image IDs

2.docker search
[root@l4 containerd]# docker search mysql NAMEDESCRIPTIONSTARSOFFICIALAUTOMATED mysqlMySQL is a widely used, open-source relation…11439[OK] mariadbMariaDB Server is a high performing open sou…4343[OK] mysql/mysql-serverOptimized MySQL Server Docker images. Create…848[OK] phpmyadminphpMyAdmin - A web interface for MySQL and M…328[OK] centos/mysql-57-centos7MySQL 5.7 SQL database server91 mysql/mysql-clusterExperimental MySQL Cluster Docker images. Cr…88 centurylink/mysqlImage containing mysql. Optimized to be link…59[OK] databack/mysql-backupBack up mysql databases to... anywhere!50 prom/mysqld-exporter42[OK] deitch/mysql-backupREPLACED! Please use http://hub.docker.com/r…41[OK] tutum/mysqlBase docker image to run a MySQL database se…35 linuxserver/mysqlA Mysql container, brought to you by LinuxSe…31 schickling/mysql-backup-s3Backup MySQL to S3 (supports periodic backup…31[OK] mysql/mysql-routerMySQL Router provides transparent routing be…22 centos/mysql-56-centos7MySQL 5.6 SQL database server20 arey/mysql-clientRun a MySQL client from a docker container18[OK] fradelg/mysql-cron-backupMySQL/MariaDB database backup using cron tas…16[OK] yloeffler/mysql-backupThis image runs mysqldump to backup data usi…7[OK] genschsa/mysql-employeesMySQL Employee Sample Database7[OK] openshift/mysql-55-centos7DEPRECATED: A Centos7 based MySQL v5.5 image…6 devilbox/mysqlRetagged MySQL, MariaDB and PerconaDB offici…3 jelastic/mysqlAn image of the MySQL database server mainta…2 ansibleplaybookbundle/mysql-apbAn APB which deploys RHSCL MySQL2[OK] centos/mysql-80-centos7MySQL 8.0 SQL database server1 widdpim/mysql-clientDockerized MySQL Client (5.7) including Curl…1[OK] [root@l4 containerd]#

搜索mysql镜像,并且STAR 大于3000
docker|docker常见命令
文章图片

Options: -f, --filter filterFilter output based on conditions provided --format stringPretty-print search using a Go template --limit intMax number of search results (default 25) --no-truncDon't truncate output

3.docker pull
Using default tag: latest#如果不写tag,默认下载最新版本 latest: Pulling from library/mysql a330b6cecb98: Pull complete #分层下载, doccker images 的核心 联合文件系统 9c8f656c32b8: Pull complete 88e473c3f553: Pull complete 062463ea5d2f: Pull complete daf7e3bdf4b6: Pull complete 1839c0b7aac9: Pull complete cf0a0cfee6d0: Pull complete 1b42041bb11e: Pull complete 10459d86c7e6: Pull complete b7199599d5f9: Pull complete 1d6f51e17d45: Pull complete 50e0789bacad: Pull complete Digest: sha256:99e0989e7e3797cfbdb8d51a19d32c8d286dd8862794d01a547651a896bcf00c#签名 Status: Downloaded newer image for mysql:latest docker.io/library/mysql:latest#真实地址

带有tag下载
docker|docker常见命令
文章图片

4.docker rmi
docker rmi -f 镜像id
[root@l4 containerd]# docker images REPOSITORYTAGIMAGE IDCREATEDSIZE mysql5.71d7aba9171692 weeks ago448MB mysqllatest0716d6ebcc1a2 weeks ago514MB ubuntulatestfb52e22af1b03 weeks ago72.8MB hello-worldlatestd1165f2212346 months ago13.3kB [root@l4 containerd]# docker rmi -f 1d7aba917169 Untagged: mysql:5.7 Untagged: mysql@sha256:d9b934cdf6826629f8d02ea01f28b2c4ddb1ae27c32664b14867324b3e5e1291 Deleted: sha256:1d7aba9171693947d53f474014821972bf25d72b7d143ce4af4c8d8484623417 Deleted: sha256:94ebbead5c58282fef91cc7d0fb56e4006a72434b4a6ae2cd5be98f369cb8c21 Deleted: sha256:989da5efad29ec59bd536cd393d277bc777f8b9b34b8e3ad9593a4b0a83b40f4 Deleted: sha256:7457ee6817c678da3cb383d27a3d79d5f3f25fbcb92958d5e8d5709e7631e23c Deleted: sha256:fe7dac53adebe33519b4e4fc577bfcddd7372cc313c35fae681fc82fb325fdc0 [root@l4 containerd]# docker images REPOSITORYTAGIMAGE IDCREATEDSIZE mysqllatest0716d6ebcc1a2 weeks ago514MB ubuntulatestfb52e22af1b03 weeks ago72.8MB hello-worldlatestd1165f2212346 months ago13.3kB [root@l4 containerd]#

删除全部的镜像
docker rmi -f $(docker images -aq)
[root@l4 containerd]# [root@l4 containerd]# docker images REPOSITORYTAGIMAGE IDCREATEDSIZE mysqllatest0716d6ebcc1a2 weeks ago514MB ubuntulatestfb52e22af1b03 weeks ago72.8MB hello-worldlatestd1165f2212346 months ago13.3kB [root@l4 containerd]# docker rmi -f $(docker images -aq) Untagged: mysql:latest Untagged: mysql@sha256:99e0989e7e3797cfbdb8d51a19d32c8d286dd8862794d01a547651a896bcf00c Deleted: sha256:0716d6ebcc1a61c5a296fcb187e71f93531e510d4e4400267e2e502103d0194c Deleted: sha256:dc895a08d34b5b81fc4ca087d2ad52cbe1a2050e249040a22c5f2eabf2f384ba Deleted: sha256:660229dcf1a452460127a498b9f3f161e7ca94507353ded8af92fe9ab55a32ed Deleted: sha256:6b26fa2fc4e2150aee2f2557bcbfaf727c00d1650ea08d8ed3fe7c8a6caaa88b Deleted: sha256:c20303553d5d2594e1655000089b12eca8db7afdcb068cc35fc47ebfe3dab5fb Deleted: sha256:77a3d69619bfea7b30831a41a32bbf61756c9f95513743deea8daa9a83ff2646 Deleted: sha256:9578f1c7f00f400b3f71be0ee721cbc0892e05e454323e1a74a6e56ae1dafdab Deleted: sha256:335f9f9fbbd8977530806ed5439a2b67f1c06117f752a2598698de4ae304c516 Deleted: sha256:e15ed274d47a7d6ddff0afcc628143254c69128a9d2379900ebb519e7c6c2bce Deleted: sha256:51930b767631b583738d75519bed2a8cc757c5b0c904617972386462deee2ca7 Deleted: sha256:43bd682fb659113a8ab168032d8f82dee86d2cee5cee2e146af6c3a6f9ccef18 Deleted: sha256:1957f1873568b423369e0299de6c9b75a111fea807b0c07506ba45d075ca8f80 Deleted: sha256:d000633a56813933cb0ac5ee3246cf7a4c0205db6290018a169d7cb096581046 Untagged: ubuntu:latest Untagged: ubuntu@sha256:9d6a8699fb5c9c39cf08a0871bd6219f0400981c570894cd8cbea30d3424a31f Deleted: sha256:fb52e22af1b01869e23e75089c368a1130fa538946d0411d47f964f8b1076180 Deleted: sha256:4942a1abcbfa1c325b1d7ed93d3cf6020f555be706672308a4a4a6b6d631d2e7 Untagged: hello-world:latest Untagged: hello-world@sha256:61bd3cb6014296e214ff4c6407a5a7e7092dfa8eefdbbec539e133e97f63e09f Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726 [root@l4 containerd]# docker images REPOSITORYTAGIMAGE IDCREATEDSIZE [root@l4 containerd]#

3.容器命令 1.docker run 启动容器命令
docker|docker常见命令
文章图片

docker run -it centos /bin/bash 启动并进入容器
[root@l4 containerd]# docker images REPOSITORYTAGIMAGE IDCREATEDSIZE centoslatest5d0da3dc97645 days ago231MB [root@l4 containerd]# docker run -it centos /bin/bash [root@bbe14e09004f /]#

docker|docker常见命令
文章图片

2.从容器中退回主机
exit 容器停止并退出
ctrl + P+Q 容器不停止退出
[root@bbe14e09004f /]# exit exit [root@l4 containerd]#

3.列出所有运行的容器
docker ps 命令
docker|docker常见命令
文章图片

[root@l4 containerd]# docker ps CONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES [root@l4 containerd]# docker ps -a CONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES bbe14e09004fcentos"/bin/bash"5 minutes agoExited (0) 3 minutes agozen_carson a8380072a23dd1165f221234"/hello"About an hour agoExited (0) About an hour agonervous_darwin 0ea914a9ad08d1165f221234"/hello"About an hour agoExited (0) About an hour agothirsty_taussig [root@l4 containerd]# docker ps -aq bbe14e09004f a8380072a23d 0ea914a9ad08 [root@l4 containerd]# docker ps -n=1 CONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES bbe14e09004fcentos"/bin/bash"6 minutes agoExited (0) 4 minutes agozen_carson [root@l4 containerd]# docker ps -n=2 CONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES bbe14e09004fcentos"/bin/bash"6 minutes agoExited (0) 4 minutes agozen_carson a8380072a23dd1165f221234"/hello"About an hour agoExited (0) About an hour agonervous_darwin

【docker|docker常见命令】4.删除容器
docker rm 容器id #删除指定容器,不能删除正在运行容器,如果要删除 rm -f docker rm -f $(docker ps -aq)#删除所有容器 docker ps-a-q | xargs docker rm#删除所有容器

5.启动和停止容器
docker|docker常见命令
文章图片

    推荐阅读