docker 镜像管理
# 下载镜像(2种方式)
[root@fan dockerfile]# docker pull nginx
[root@fan dockerfile]# docker pull nginx:1.20.5
# 查看所有镜像
[root@fan dockerfile]# docker images
# 删除镜像(2种方式)
[root@fan dockerfile]# docker rmi nginx:1.20.5
[root@fan dockerfile]# docker rmi 75d4f2e88777
# 推送镜像至仓库
[root@fan dockerfile]# docker tag nginx:1.20.5 mynginx.com/nginx:1.20.5 #先将本地镜像加上标准标签
[root@fan dockerfile]# docker login #登录镜像仓库
[root@fan dockerfile]# docker push mynginx.com/nginx:1.20.5
docker 容器管理
# 运行容器 --restart=alwasys 容器开机自启 -p [主机端口]:[镜像端口]
[root@fan dockerfile]# docker run -it --restart=alwasys -p 88:80 -v 主机路径:容器内路径 –name my-nginx nginx:1.20.5 /bin/bash
# 另一种方式,通过更新解决容器选项
[root@fan dockerfile]# docker update nginx:1.20.5 --restart=alwasys
# 查看运行中的容器
[root@fan dockerfile]# docker ps
# 查看所有容器
[root@fan dockerfile]# docker ps -a
# 删除容器,-f 强制删除,无-f 状态下只能删除已停止的容器
[root@fan dockerfile]# docker rm -f nginx:1.20.5
[root@fan dockerfile]# docker rm -f 75d4f2e88777
# 进入容器内部
[root@fan dockerfile]# docker exec -it 75d4f2e88777 /bin/bash
#
[root@fan dockerfile]# docker commit -a "abc@abc.com" -m "改变内容" 容器ID 新镜像:tag
# 查看日志,拍错
[root@fan dockerfile]# docker logs 容器名:容器ID
docker 的镜像打包
# 导出镜像,默认格式为tar格式
[root@fan dockerfile]# docker save -o new_images.tar centos:v1
# 将new_images.tar文件中镜像导入系统
[root@fan dockerfile]# docker load -i new_images.tar