Docker_03 docker的常用命令
1、docker version //docker的信息
2、docker info //显示docker 的系统信息,包括镜像和容器
3、docker --help //命令帮助
4、命令帮助文档:https://docs.docker.com/reference/build-checks/
5、镜像命令
docker images
REPOSITORY(镜像的仓库) TAG(镜像的标签) IMAGE ID(镜像的id) CREATED(镜像的创建时间) SIZE
docker image ls [OPTIONS] [REPOSITORY[:TAG]]
-a, --all Show all images (default hides intermediate images)
--digests Show digests
-f, --filter Filter output based on conditions provided
--format Format output using a custom template:
'table': Print output in table format with column headers (default)
'table TEMPLATE': Print output in table format using the given Go template
'json': Print in JSON format
'TEMPLATE': Print output using the given Go template.
Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates
--no-trunc Don't truncate output
-q, --quiet Only show image IDs
--tree API 1.47+ experimental (CLI) List multi-platform images as a tree (EXPERIMENTAL)
docker search
| -f, --filter | Filter output based on conditions provided |
| ---- | ---- |
| --format | Pretty-print search using a Go template |
| --limit | Max number of search results |
| --no-trunc | Don't truncate output |
docker pull
docker image pull [OPTIONS] NAME[:TAG|@DIGEST]
指定版本下载: docker pull MySQL:5.7 //需要有tag,不然会下载最新版本
| Option | Default | Description |
| ---- | ---- | ---- |
| -a, --all-tags | | Download all tagged images in the repository |
| --disable-content-trust | true | Skip image verification |
| --platform | | API 1.32+ Set platform if server is multi-platform capable |
| -q, --quiet | | Suppress verbose output |
docker remove
docker rmi -f 镜像id //删除单个镜像
docker rmi -f 镜像id1 镜像id1 镜像id1 //删除多个镜像
docker rmi -f $(docker images -aq) //删除所有的镜像并且列出来
6、容器命令
有镜像才能创建容器
docker pull centos 下载centos
docker run
-d 容器名 //后台启动后 没有前台应用就会自动结束
docker container run [OPTIONS] IMAGE [COMMAND] [ARG...]
测试:
a、docker run it cnetos /bin/bash //进入容器
b、ls //容器内是个服务器 基本版本
c、exit //退出容器
CTRL+p+q //容器不停止退出
docker ps 列出正在运行的容器
-a
-n=?
-q 显示容器的编号
docker rm 容器id //删除特定容器 不能删除正在运行的, rm -f 强制删除
docker rm -f // docker rm -f $(docker ps -aq) 删除并且列出
docker ps -a -q|xags docker rm //删除所有容器
启动和停止容器的操作
docker start 容器id //启动
docker stop 容器id //停止
docker restart 容器id //重启
docker kill //删除
日志
docker logs [可选参数] 容器id
-f
-t 时间戳
--tail number 几条
docker inspect 容器id 查看镜像的元数据
docker top 容器id 查看容器的进程信息