1.docker version #显示docker的版本信息
2.docker info # 显示docker额系统信息,包括镜像和容器数量
3. docker 命令 --help
官网文档地址
https://docs.docker.com/engine/reference/commandline/docker/
REPOSITORY 镜像的仓库源
TAG 镜像的标签
IMAGE ID 镜像的id
CREATED 镜像的创建时间
SIZE 镜像的大小
Options:
-a, --all Show all images (default hides intermediate images)
--digests Show digests
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print images using a Go template
--no-trunc Don't truncate output
-q, --quiet Only show image IDs
2.docker search
[root@l4 containerd]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11439 [OK]
mariadb MariaDB Server is a high performing open sou… 4343 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 848 [OK]
phpmyadmin phpMyAdmin - A web interface for MySQL and M… 328 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 91
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 88
centurylink/mysql Image containing mysql. Optimized to be link… 59 [OK]
databack/mysql-backup Back up mysql databases to... anywhere! 50
prom/mysqld-exporter 42 [OK]
deitch/mysql-backup REPLACED! Please use http://hub.docker.com/r… 41 [OK]
tutum/mysql Base docker image to run a MySQL database se… 35
linuxserver/mysql A Mysql container, brought to you by LinuxSe… 31
schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 31 [OK]
mysql/mysql-router MySQL Router provides transparent routing be… 22
centos/mysql-56-centos7 MySQL 5.6 SQL database server 20
arey/mysql-client Run a MySQL client from a docker container 18 [OK]
fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron tas… 16 [OK]
yloeffler/mysql-backup This image runs mysqldump to backup data usi… 7 [OK]
genschsa/mysql-employees MySQL Employee Sample Database 7 [OK]
openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6
devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offici… 3
jelastic/mysql An image of the MySQL database server mainta… 2
ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 2 [OK]
centos/mysql-80-centos7 MySQL 8.0 SQL database server 1
widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl… 1 [OK]
[root@l4 containerd]#
Options:
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print search using a Go template
--limit int Max number of search results (default 25)
--no-trunc Don'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下载
4.docker rmi
docker rmi -f 镜像id
[root@l4 containerd]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 1d7aba917169 2 weeks ago 448MB
mysql latest 0716d6ebcc1a 2 weeks ago 514MB
ubuntu latest fb52e22af1b0 3 weeks ago 72.8MB
hello-world latest d1165f221234 6 months ago 13.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
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 0716d6ebcc1a 2 weeks ago 514MB
ubuntu latest fb52e22af1b0 3 weeks ago 72.8MB
hello-world latest d1165f221234 6 months ago 13.3kB
[root@l4 containerd]#
删除全部的镜像
docker rmi -f $(docker images -aq)
[root@l4 containerd]#
[root@l4 containerd]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 0716d6ebcc1a 2 weeks ago 514MB
ubuntu latest fb52e22af1b0 3 weeks ago 72.8MB
hello-world latest d1165f221234 6 months ago 13.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
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@l4 containerd]#
docker run -it centos /bin/bash 启动并进入容器
[root@l4 containerd]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5d0da3dc9764 5 days ago 231MB
[root@l4 containerd]# docker run -it centos /bin/bash
[root@bbe14e09004f /]#
2.从容器中退回主机
exit 容器停止并退出
ctrl + P+Q 容器不停止退出
[root@bbe14e09004f /]# exit
exit
[root@l4 containerd]#
[root@l4 containerd]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@l4 containerd]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bbe14e09004f centos "/bin/bash" 5 minutes ago Exited (0) 3 minutes ago zen_carson
a8380072a23d d1165f221234 "/hello" About an hour ago Exited (0) About an hour ago nervous_darwin
0ea914a9ad08 d1165f221234 "/hello" About an hour ago Exited (0) About an hour ago thirsty_taussig
[root@l4 containerd]# docker ps -aq
bbe14e09004f
a8380072a23d
0ea914a9ad08
[root@l4 containerd]# docker ps -n=1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bbe14e09004f centos "/bin/bash" 6 minutes ago Exited (0) 4 minutes ago zen_carson
[root@l4 containerd]# docker ps -n=2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bbe14e09004f centos "/bin/bash" 6 minutes ago Exited (0) 4 minutes ago zen_carson
a8380072a23d d1165f221234 "/hello" About an hour ago Exited (0) About an hour ago nervous_darwin
4.删除容器
docker rm 容器id #删除指定容器,不能删除正在运行容器,如果要删除 rm -f
docker rm -f $(docker ps -aq) #删除所有容器
docker ps -a -q | xargs docker rm #删除所有容器
5.启动和停止容器