镜像的构建和分享
- 镜像构建:
docker image build --tag=[dockerhub-id]/[image-name]:[tag] - 镜像分享:
- 使用
docker image save/load将镜像保存在本地磁盘,其他用户使用硬盘拷贝镜像然后本地加载; - 使用
docker image push [dockerhub-id]/[image-name]:[tag]将镜像上传到 DockerHub 上,其他用户使用docker image pull [dockerhub-id]/[image-name]:[tag]拉取镜像。
- 使用
docker image build
构建镜像:
docker image build -t [image-name]:[tag] .- 构建镜像时推荐指明
[tag],如果未指明后期需要使用docker image tag [old-image-name] [new-image-name]:[tag]命令对本地镜像打一个 tag。 - 如果需要上传 dockerhub:
docker image build -t [dockerhub-id]/[image-name]:[tag] .。

hello.py文件print("hello docker, hello jaime~")Dockerfile文件FROM ubuntu:22.04: 基础镜像 ubuntu:22.04;RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y python3.9 python3-pip: 安装依赖;COPY hello.py /:复制文件;CMD ["python3", "/hello.py"]: 启动时运行命令。
FROM ubuntu:22.04 RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y python3.9 python3-pip COPY hello.py / CMD ["python3", "/hello.py"]
docker image push
- docker 登录:
docker login -u [username],密码为 账户密码或 token。 - 本地镜像打一个 tag:
docker image tag [old-image-name] [new-image-name]:[tag] - 推送本地镜像到 dockerhub:
docker image push [dockerhub-id]/[image-name]:[tag] - 拉取 dockerhub 镜像:
docker image pull [dockerhub-id]/[image-name]:[tag]

Backlinks
Docker Notes
- 镜像的构建和分享 [[image-build-push]]