docker 常用命令
1 帮助命令
docker version #查看docker 版本号
docker info #显示docker的系统信息
docker 命令---help #帮助命令
官方帮助文档的地址:https://docs.docker.com/engine/reference/commandline/docker/
2. 镜像命令
docker images # 查看docker的所有镜像
[root@node137 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpress 5.6.2-php8.0-fpm-alpine 4f895053d19a 7 days ago 199MB
wordpress 5.6.2-php8.0-apache c20bbace0d72 7 days ago 519MB
php74 v01 a087bbc55f6f 9 days ago 176MB
php72 v01 ec4be205b9cf 9 days ago 176MB
<none> <none> 289c85477c88 9 days ago 176MB
mysql 5.7.33 a70d36bc331a 6 weeks ago 449MB
alpine latest 7731472c3f2a 6 weeks ago 5.61MB
redis latest 621ceef7494a 6 weeks ago 104MB
REPOSITORY #镜像的仓库源
TAG #镜像的标签
IMAGE ID #镜像的ID
CREATED #镜像的创建时间
SIZE #镜像大小
2.1可选项
--all , -a #列出所有镜像
--filter , -f #过滤
--quiet , -q #只显示镜像的ID
# docker search 搜索镜像
[root@node137 ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 10565 [OK]
mariadb MariaDB Server is a high performing open sou… 3947 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 774 [OK]
2.2选项 ,通过收藏来过滤
filter=STARS=3000 #搜索出来的镜像就是STARS大于 3000的
[root@node137 ~]# docker search mysql --filter=STARS=3000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 10565 [OK]
mariadb MariaDB Server is a high performing open sou… 3947 [OK]
2.3下载镜像
docker pull #下载镜像
[root@node137 ~]# docker pull mysql 可以在后面加版本号
Using default tag: latest # 默认使用最新版
latest: Pulling from library/mysql
a076a628af6f: Already exists #分层下载 docker images的核心 联合文件系统
f6c208f3f991: Already exists #显示这个说明这个分层已经存在,不需要重复下载
88a9455a9165: Already exists
406c9b8427c6: Already exists
7c88599c0b25: Already exists
25b5c6debdaf: Already exists
43a5816f1617: Already exists
1a8c919e89bf: Pull complete #显示这个说明,这个分层没有存在,正在下载中。。。
9f3cf4bd1a07: Downloading [=================> ] 39.9MB/113.1MB
Digest: sha256:feada149cb8ff54eade1336da7c1d080c4a1c7ed82b5e320efb5beebed85ae8c #签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest #真实地址
2.4价于它
docker pull mysql
docker.io/library/mysql:latest
3 .删除镜像 docker rmi -f +指定镜像或者ID
[root@node137 ~]# docker rmi -f mysql:latest
Untagged: mysql:latest
Untagged: mysql@sha256:feada149cb8ff54eade1336da7c1d080c4a1c7ed82b5e320efb5beebed85ae8c
Deleted: sha256:c8562eaf9d81c779cbfc318d6e01b8e6f86907f1d41233268a2ed83b2f34e748
Deleted: sha256:1b649b85960473808c6b812fc30c3f6a3ff1c0ffdcba5c9435daf01cf7d5373a
Deleted: sha256:19cc889447050c16c797fd209fa114ee219de23facb37c00d4137a4ed4aad922
Deleted: sha256:3c793c06a026d276cf56a6a6a75527026ed9eafa7a7d21a438f7d5ed2314148e
Deleted: sha256:1e1cd89a2bc183a7fea3dab0b543e9924278321ad0921c22cc088adbf3c2e77b
Deleted: sha256:83b2015dfd000588c7c947b2d89b3be7a8e5a3abc6ab562668c358033aa779ec
删除全部镜像
docker rmi -f $(docker images -aq)
4. 容器命令
说明:我们有了镜像才能创建容器。linux 下载一个centos j镜像来测试学习
docker pull centos
4.1 新建容器并启动
docker run [可选参数] image
4.2参数说明javascript
name='Name'容器名字 用来区分容器
-d 后台方式运行
-it 使用交互方式运行,进入容器查看内容
-p 指定容器的端口 -p 8080:8080
-P (大写) 随机指定端口
4.3# 启动并进入容器
[root@node137 ~]# docker run -it centos bash
[root@bbc1a6d03523 /]#
4.4 列出所有的运行容器
docker ps 命令---help
4.5列出当前正在运行的容器javascript
-a # 列出当前正在运行的容器+带出历史运行过的容器
-n=? # 显示最近创建的容器
-q #只显示容器的编号
[root@node137 ~]# docker ps -n=2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bbc1a6d03523 centos "bash" 24 minutes ago Exited (127) 2 minutes ago romantic_payne
4a354bd50254 wordpress:5.6.2-php8.0