Docker 学习笔记(三)镜像的创建管理和发布
目录
1. 镜像的获取

三种方式:
- pull from
registry(online) 从registry拉取
- public(公有)
- private(私有)
- build from
Dockerfile(online) 从Dockerfile构建 - load from
file(offline) 文件导入 (离线)
2. Registry
3. 镜像的基本操作
- 拉取镜像:
docker image pull name[:tag],docker image pull quay.io/bitnami/nginx - 查看镜像:
docker image ls - 镜像详情:
docker image inspect <ID or Name> - 删除镜像:
docker image rm <ID or Name>
4. 镜像的导出和导入 (offline)
- 导出:
docker image save <ID or Name> -o <path_to_file> - 导入:
docker image load -i <path_to_file>
5. Dockerfile 介绍
Dockerfile 基本结构:
| |
FROM:基础镜像RUN:执行命令ADD:添加文件CMD:启动容器执行的命令
6. 镜像的构建和分享
- 构建:
docker image build -t <name>[:tag] <path_to_dockerfile> - 通过存在的 image 添加 tag:
docker image tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] - 登录:
docker login - push:
docker image push <Name>[:tag](要把 image name 构建成docker-hub-account-name/image-name[:tag]才能 push 到自己的仓库)
7. 通过 commit 创建镜像
对容器的操作会保存到容器中,可以通过 docker container commit CONTAINER [REPOSITORY[:TAG]] 来创建镜像,相当于保存当前容器
8. scratch 镜像
- 查看镜像分层:
docker image history <image>
