Docker容器创建镜像并提交到Docker Hub

1. 将容器提交为镜像

docker commit -a "author" -m "some message" {
    
    container id} {
    
    image name}:{
    
    version}
  • -a:作者
  • -m:描述
  • container id:容器的iddocker ps中查看
  • image name:镜像名称
  • version:版本号

例如:

docker commit -a "Tom" -m "first commit" 45c7b841b0a8 ubuntu-dev:v1.0

运行上述命令之后运行docker images,将会出现一个新的镜像

REPOSITORY		TAG		IMAGE ID
ubuntu-dev		1.0		6939616dfb23

2. 登录Docker Hub

docker login
# username:
# password:

3. 修改镜像名称

docker tag {
    
    image id} {
    
    username}/{
    
    image name}:{
    
    version}
  • image id:镜像的iddocker images中查看
  • username:Docker Hub的账户名
  • image name:你希望它在Docker Hub中显示的名称
  • version:版本号

例如:

docker tag 6939616dfb23 tom/ubuntu-dev:v1.0

修改完后运行docker images查看一下修改之后的镜像

REPOSITORY		TAG		IMAGE ID
ubuntu-dev		1.0		6939616dfb23
tom/ubuntu-dev	1.0		6939616dfb23

4. 推送镜像至Docker Hub仓库

docker push tom/ubuntu-dev:latest

猜你喜欢

转载自blog.csdn.net/cacique111/article/details/127755983