首页 > 其他 > 详细

012、构建镜像(2018-12-29 周六)

时间:2018-12-30 00:11:55      阅读:183      评论:0      收藏:0      [点我收藏+]
 
在使用Docker的时候,几乎所有的操作系统和应用程序都有现成的镜像,比如centos、debian、ubuntu、nginx、jenkins。直接docker pull 即可。
 
Docker Hub上的官方镜像已经帮我们做好了应用程序的配置和优化工作,一般情况下直接使用即可。
 
如果Docker Hub上找不到我们需要的镜像,比如自己开发的程序,那就需要自己构建镜像了。
 
构建镜像的方法有两种:1、docker commit 命令构建;2、Dockerfile文件构建
 
docker commit
 
这种方法构建镜像比较简单直观
    1、运行容器
    2、修改容器
    3、将容器保存为镜像
 
下面是一个基于centos base镜像构建vim镜像的过程
 
 
root@docker-lab:~# docker run -it centos
Unable to find image ‘centos:latest‘ locally
latest: Pulling from library/centos
a02a4930cb5d: Pull complete
Digest: sha256:38777a4106f0072649128ea4236241345a3ed21c55abbbd53bad5342549f6126
Status: Downloaded newer image for centos:latest
[root@02d010de5fe9 /]# wget
bash: wget: command not found
[root@02d010de5fe9 /]# yum install -y wget
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: mirrors.neusoft.edu.cn
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
=============================================================================================================================================================
Package                            Arch                                 Version                                    Repository                          Size
=============================================================================================================================================================
Installing:
wget                               x86_64                               1.14-18.el7                                base                               547 k
 
Transaction Summary
=============================================================================================================================================================
Install  1 Package
 
Total download size: 547 k
Installed size: 2.0 M
Downloading packages:
wget-1.14-18.el7.x86_64.rpm                                                                                                           | 547 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : wget-1.14-18.el7.x86_64                                                                                                                   1/1
install-info: No such file or directory for /usr/share/info/wget.info.gz
  Verifying  : wget-1.14-18.el7.x86_64                                                                                                                   1/1
 
Installed:
  wget.x86_64 0:1.14-18.el7                                                                                                                                  
 
Complete!
[root@02d010de5fe9 /]# wget
wget: missing URL
Usage: wget [OPTION]... [URL]...
 
Try `wget --help‘ for more options.
 
root@docker-lab:~# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
02d010de5fe9        centos              "/bin/bash"         5 minutes ago       Up 5 minutes                            vibrant_bhabha
root@docker-lab:~# docker commit
"docker commit" requires at least 1 and at most 2 arguments.
See ‘docker commit --help‘.
 
Usage:  docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] [flags]
 
Create a new image from a container‘s changes
root@docker-lab:~# docker commit vibrant_bhabha centos-wget
sha256:7fe32c85b3a25ed750373af73dd808600c1e0112b96ddade85a01532cce0f2f3
root@docker-lab:~# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos-wget         latest              7fe32c85b3a2        13 seconds ago      328MB
centos              latest              1e1148e4cc2c        3 weeks ago         202MB
root@docker-lab:~# docker run -it centos-wget
[root@2e47049d7633 /]# wget     
wget: missing URL
Usage: wget [OPTION]... [URL]...
 
Try `wget --help‘ for more options.
[root@2e47049d7633 /]#
 
docker commit 构建镜像,不是推荐的方法:1、手工操作,效率,容易出错;2、使用者不清楚构建的过程,无法进行审计,存在安全隐患
 
建议使用Dockerfile 构建镜像
 

012、构建镜像(2018-12-29 周六)

原文:https://www.cnblogs.com/www1707/p/10197248.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!