使用commit命令创建Docker镜像

目的

将对容器的变更保存并提交到自己的镜像仓库中

前提条件

  • 1 安装Docker
  • 2 注册DockerHub用户
  • 3 下载容器镜像

实施

  1. 对容器修改并提交

例如在当前容器中安装pip

[root@b9bc56403642 /]# python get-pip.py 
Collecting pip
 Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
   100% |################################| 1.3MB 13kB/s 
Collecting setuptools
 Downloading setuptools-36.2.0-py2.py3-none-any.whl (477kB)
   100% |################################| 481kB 13kB/s 
Collecting wheel
 Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
   100% |################################| 71kB 14kB/s 
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-9.0.1 setuptools-36.2.0 wheel-0.29.0
[root@b9bc56403642 /]# pip -V
pip 9.0.1 from /usr/lib/python2.7/site-packages (python 2.7)

退出容器

[root@b9bc56403642 /]# exit        
exit

提交修改

docker@default:~$ sudo docker commit b9b teitiyuu/atp-centos
sha256:1ac7fcc09ecd9878e528db9f38df635d441cffe0f5c4879c188d4115d657fe93
docker@default:~$ docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
teitiyuu/atp-centos   latest              1ac7fcc09ecd        11 seconds ago      313MB
daocloud.io/centos    latest              8140d0c64310        2 months ago        193MB
  1. DockerHub用户登录
docker@default:~$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: teitiyuu
Password: 
Login Succeeded
  1. 提交镜像
docker@default:~$ docker push teitiyuu/atp-centos:latest
The push refers to a repository [docker.io/teitiyuu/atp-centos]
b2d6ace8e407: Pushed 
b51149973e6a: Pushed 
latest: digest: sha256:ebbc18663b17a566f3cb479e364f354db85e9945ae3f2b2e660d47258059f79f size: 741
docker@default:~$ 
  1. DockerHub
使用commit命令创建Docker镜像_第1张图片

你可能感兴趣的:(使用commit命令创建Docker镜像)