You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
940 B
Bash

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
# 定义需要提交的容器列表
containers=("myubuntu")
for container in "${containers[@]}"; do
# 为每个容器 commit 为镜像,并获取新的镜像 ID
new_image_id=$(docker commit $container chunlinwang/$container:latest)
echo "生成新镜像 ID$new_image_id"
# 登录到 Docker Hub
echo "Docker Hub 登录"
docker login -u chunlinwang -p 252515144
# 提交镜像到 Docker Hub
echo "推送镜像 $container 到 Docker Hub"
docker push chunlinwang/$container:latest
# 删除旧的无标签镜像以节约空间
# 这里使用 docker image prune -f 命令删除所有悬空dangling的镜像
echo "删除悬空镜像,释放空间"
docker image prune -f
done
# 退出 Docker Hub 登录(如果需要)并清理其他未使用的资源
# docker logout
echo "执行系统级清理,删除未使用的容器、镜像、网络和卷"
docker system prune -a --volumes -f