镜像相关的命令
镜像名称分为两部分组成:[repository]:[tag],tag就是镜像的版本。如果tag没有指定默认就是latest,表示最新版本的镜像。

查看docker命令的帮助信息
docker --help
具体某条命令的帮助信息
docker images --help
案例一:从DockerHub中拉取一个nginx镜像并查看
拉取docker nginx镜像命令:docker pull nginx
docker images 查看所有镜像命令

docker images | grep nginx查找nginx镜像的命令

docker save -o nginx.tar nginx:latest 保存nginx镜像为tar压缩文件命令

docker rmi [repository]:[tag] 删除镜像命令
docker rmi 容器id 也可以删除镜像命令

docker load -i nginx.tar加载压缩文件为镜像文件

容器相关命令

创建并运行一个容器命令:
docker run --name containerName -p 80:80 -d nginx
docker run 创建并运行一个容器
--name 给容器起一个名字
-p 宿主机端口:容器映射端口
-d 后台运行容器
nginx 镜像名称,没写tag,表示nginx:latest

docker ps 命令查看所有启动的容器命令
docker ps -a 命令查看所有容器命令
docker ps -a | grep nginx 命令查看所有与nginx相关的容器命令


查看容器日志命令:docker logs 容器名

持续不断地输出日志命令:docker logs 容器名 -f

**案例二:**进入nginx容器,修改html文件内容,添加"卷土重来"。
进入容器命令: docker exec -it 容器名称 bash
docker exec 进入容器内部执行一个命令。
-it 给当前进入容器创建一个标准的输入、输出终端,允许我们与容器交互。
bash 进入容器后执行的命令,bash是一个linux终端交互命令。


**问题:**进入容器后发现vi命令无法使用,因为容器是一个阉割版的linux。
执行修改内容命令:
sed -i 's#Welcome to nginx#卷土重来#g' index.html
sed -i 's#<head>#<head><meta charset="utf-8">#g' index.html


docker rm 容器名称
不能删除正在运行中的容器。可以采用强制删除命令:docker rm -f 容器名称

启动并创建redis容器的命令:
docker run --name myredis -p 16379:6379 -d redis redis-server --appendonly yes
redis-server --appendonly yes redis持久化方式AOF

进入redis容器,并执行redis-cli客户端命令, 存入num的值为666:
