Docker常用命令
文档地址 https://docs.docker.com/reference/
帮助命令
docker version
docker info
docker --help
镜像命令
- docker images
[root@VM-0-9-centos /]
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 5a4e492065c7 5 days ago 514MB
hello-world latest d1165f221234 5 months ago 13.3kB
centos latest 300e315adb2f 8 months ago 209MB
注释: REPOSITORY?镜像的仓库名称 TAG ?????版本标签 IMAGE ID ???镜像id CREATED???镜像的创建时间 SIZE ????? 镜像的大小
可选项: -a ,–all ??? #列出所有的镜像 -q , --quiet ? #只显示镜像的id
- docker search 搜索镜像
[root@VM-0-9-centos /]
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11308 [OK]
mariadb MariaDB Server is a high performing open sou… 4297 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 838 [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! 46
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… 30 [OK]
mysql/mysql-router MySQL Router provides transparent routing be… 21
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]
openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6
cytopia/mysql-5.5 MySQL 5.5 on CentOS 7 4 [OK]
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
vitess/mysqlctld vitess/mysqlctld 1 [OK]
widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl… 1 [OK]
monasca/mysql-init A minimal decoupled init container for mysql 0
可选项: –filter=STARS=3000 搜索出来的镜像STARS大于3000
[root@VM-0-9-centos /]
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11308 [OK]
mariadb MariaDB Server is a high performing open sou… 4297 [OK]
- docker pull 下载镜像
[root@VM-0-9-centos /]
Using default tag: latest
latest: Pulling from library/mysql
e1acddbe380c: Pull complete
bed879327370: Pull complete
03285f80bafd: Pull complete
ccc17412a00a: Pull complete
1f556ecc09d1: Pull complete
adc5528e468d: Pull complete
1afc286d5d53: Pull complete
6c724a59adff: Pull complete
0f2345f8b0a3: Pull complete
c8461a25b23b: Pull complete
3adb49279bed: Pull complete
77f22cd6c363: Pull complete
Digest: sha256:d45561a65aba6edac77be36e0a53f0c1fba67b951cb728348522b671ad63f926
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
注: docker pull 镜像名称 [版本号,默认最新]
- docker rmi 删除镜像
[root@VM-0-9-centos /]
Untagged: mysql:latest
Untagged: mysql@sha256:d45561a65aba6edac77be36e0a53f0c1fba67b951cb728348522b671ad63f926
Deleted: sha256:5a4e492065c722ec8cc7413552bafc6fd5434c5ad90797e898ccc4e347e21aa5
Deleted: sha256:816bf92c28337cd97393cb1fab7697398c9b657baa8e80ad394e1193bdd7c323
Deleted: sha256:4d9cad11f64589b397b1033d6f14cea1794efbee0a9923932fb3394a67cb9812
Deleted: sha256:d8cc28a31b469770ffe2239a29aaef8745fedc4df3c545b1615ba864796709a3
Deleted: sha256:c65a377e07f1205f3c28f7067d2ac4da3a65fbe7c1b4606b48028db3818d2f4c
Deleted: sha256:7dcd840f1d4be1a565f470453489932a17c62ed36b959d7839f004606ba22f0b
Deleted: sha256:1438a7497295aed687ea1875073a1f9faa6a308f787767b952da4a1a21e2c2c6
Deleted: sha256:c728863b4742db55b9630b0129abac718c8c9704e5ed86e8af93dfb47a0f6214
Deleted: sha256:0f12df3ff796b6fb619c63bf2f78f16d1033746e19f75ffc2d8d72ea69242ad4
Deleted: sha256:3072318e40ebff019298a59290e615ad6170a651f3121c0e356dcf3dd7426136
Deleted: sha256:a69e3133dd3c0a81bd439120abb8f98e43c1581629896725b968db906c8fdfac
Deleted: sha256:6d9498fd63c38c4b0b9bbc563087b4bc164b2fb5211832a8d43c60a9692a7f84
Deleted: sha256:f68ef921efae588b3dd5cc466a1ca9c94c24785f1fa9420bea15ecc2dedbe781
docker rmi -f 镜像id # 删除指定的镜像 docker rmi -f 镜像id 镜像id 镜像id # 删除多个镜像 docker rmi -f $(docker images -aq)镜像id # 删除q全部的镜像
容器命令
… 1.如拉取一个centos镜像
docker pull centos
[root@VM-0-9-centos ~]
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 5 months ago 13.3kB
[root@VM-0-9-centos ~]
Using default tag: latest
latest: Pulling from library/centos
7a0437f04f83: Pull complete
Digest: sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
2.新建容器启动 docker run -it centos
docker run -it centos
注释:参数说明 –name=“名字” ???? 指定容器名字 -d ?????????后台方式运行 -it ??????? 使用交互方式运行,进入容器查看内容 -p ???? 指定容器的端口 ( -p ip:主机端口:容器端口 配置主机端口映射到容器端口 -p 主机端口:容器端口 -p 容器端口 ) -P ???? 随机指定端口(大写的P)
[root@VM-0-9-centos /]
d63526a50c3ce8a5fbb3355751b494a251ce06ebff3e65e22690c020117f88a3
3.查看当前运行的容器
[root@VM-0-9-centos /]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d63526a50c3c centos "/bin/bash" 43 seconds ago Up 42 seconds centos2
4.列出所有的容器,包括历史运行的
[root@VM-0-9-centos /]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
68e06d8c2ffe centos "/bin/bash" 3 minutes ago Exited (0) 3 minutes ago crazy_boyd
d63526a50c3c centos "/bin/bash" 8 minutes ago Up 8 minutes centos2
357a30ab3591 centos "/bin/bash" 14 minutes ago Exited (0) 14 minutes ago centos1
5.退出容器 exit
[root@d63526a50c3c /]
exit
快捷键退出 ctrl + q + p :退出之后容器不停止
6.删除容器
[root@VM-0-9-centos /]
357a30ab3591
6722dc6104aa
4f5d69fe66a0
ada3b1757503
d11499834f55
4b7e62f10f2f
751cb0d4ecaf
e765be63a67a
Error response from daemon: You cannot remove a running container d63526a50c3ce8a5fbb3355751b494a251ce06ebff3e65e22690c020117f88a3. Stop the container before attempting removal or force remove
在运行的容器不能删除,或者强制删除 docker rm -f
[root@VM-0-9-centos /]
d63526a50c3c
7.启动容器 docker start 容器id
[root@VM-0-9-centos /]
dd8e964dc3c2
docker start 和docker run 的区别: docker satat :重新启动一个关闭的容器 docker run :根据镜像启动一个容器
8.停止容器
docker stop ??容器id docker kill ???容器id
[root@VM-0-9-centos /]
e160eb260ebd
docker stop 和docker kill 两者都是关闭容器, docker stop:允许其在一定时间(默认10s)内进行一些操作(例如资源回收),若这段时间内容器未停止,则发送SIGKILL信号强行杀死容器。 docker kill: 直接发送SIGKILL信号杀死容器
9.重启容器 docker restart 容器id
[root@VM-0-9-centos /]
e160eb260ebd
|