012构建镜像(2018-12-29 周六)
Posted www1707
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了012构建镜像(2018-12-29 周六)相关的知识,希望对你有一定的参考价值。
在使用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镜像的过程
[email protected]:~# 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
[[email protected] /]# wget
bash: wget: command not found
[[email protected] /]# 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!
[[email protected] /]# wget
wget: missing URL
Usage: wget [OPTION]... [URL]...
Try `wget --help‘ for more options.
[email protected]:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
02d010de5fe9 centos "/bin/bash" 5 minutes ago Up 5 minutes vibrant_bhabha
[email protected]:~# 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
[email protected]:~# docker commit vibrant_bhabha centos-wget
sha256:7fe32c85b3a25ed750373af73dd808600c1e0112b96ddade85a01532cce0f2f3
[email protected]:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos-wget latest 7fe32c85b3a2 13 seconds ago 328MB
centos latest 1e1148e4cc2c 3 weeks ago 202MB
[email protected]:~# docker run -it centos-wget
[[email protected] /]# wget
wget: missing URL
Usage: wget [OPTION]... [URL]...
Try `wget --help‘ for more options.
[[email protected] /]#
docker commit 构建镜像,不是推荐的方法:1、手工操作,效率,容易出错;2、使用者不清楚构建的过程,无法进行审计,存在安全隐患
建议使用Dockerfile 构建镜像
以上是关于012构建镜像(2018-12-29 周六)的主要内容,如果未能解决你的问题,请参考以下文章