commit

  • 用法
  1. Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
  2. Create a new image from a container's changes
  3. -a, --author= Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  4. -c, --change=[] Apply Dockerfile instruction to the created image
  5. --help=false Print usage
  6. -m, --message= Commit message
  7. -p, --pause=true Pause container during commit
  • 例子
  1. $ sudo docker ps
  2. ID IMAGE COMMAND CREATED STATUS PORTS
  3. c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
  4. 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
  5. $ sudo docker commit c3f279d17e0a SvenDowideit/testimage:version3
  6. f5283438590d
  7. $ sudo docker images | head
  8. REPOSITORY TAG ID CREATED VIRTUAL SIZE
  9. SvenDowideit/testimage version3 f5283438590d 16 seconds ago 335.7 M

提交一个重新配置过的容器到镜像

  1. $ sudo docker ps
  2. ID IMAGE COMMAND CREATED STATUS PORTS
  3. c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
  4. 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
  5. $ sudo docker inspect -f "{{ .Config.Env }}" c3f279d17e0a
  6. [HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]
  7. $ sudo docker commit --change "ENV DEBUG true" c3f279d17e0a SvenDowideit/testimage:version3
  8. f5283438590d
  9. $ sudo docker inspect -f "{{ .Config.Env }}" f5283438590d
  10. [HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DEBUG=true]
  • 总结

这个命令的用处在于把有修改的container提交成新的Image,然后导出此Imange分发给其他场景中调试使用。Docker官方的建议是,当你在调试完Image的问题后,应该写一个新的Dockerfile文件来维护此Image。commit命令仅是一个临时创建Imange的辅助命令。