docker入门(二)
打造自己的镜像
首先我们启动busybox镜像为容器,在该容器中安装一个小工具,再将这个容器保存为新的镜像
首先我们下载一个镜像,再启动容器
[root@centos ~]# docker pull learn/tutorial
Using default tag: latest
Trying to pull repository docker.io/learn/tutorial ...
latest: Pulling from docker.io/learn/tutorial
271134aeb542: Pull complete
Digest: sha256:2933b82e7c2a72ad8ea89d58af5d1472e35dacd5b7233577483f58ff8f9338bd
Status: Downloaded newer image for docker.io/learn/tutorial:latest
[root@centos ~]# docker run -d -it --name=tutorial docker.io/learn/tutorial /bin/bash
87370a9b56b0810257f8172b82b1e219c15b2a0999ad6703d4da28fc1e5d992f
[root@centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
87370a9b56b0 docker.io/learn/tutorial "/bin/bash" 2 minutes ago Up 2 minutes tutorial
进入这个容器
[root@centos ~]# docker exec -it tutorial bash
root@87370a9b56b0:/#
默认tutorial是不带ping工具的,我们下载一个ping
root@87370a9b56b0:/# ping www.baidu.com
bash: ping: command not found
root@87370a9b56b0:/# apt-get install -y ping
Reading package lists... Done
Building dependency tree... Done
Note, selecting 'iputils-ping' instead of 'ping'
The following NEW packages will be installed:
iputils-ping
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 56.1 kB of archives.
After this operation, 143 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ precise/main iputils-ping amd64 3:20101006-1ubuntu1 [56.1 kB]
Fetched 56.1 kB in 15s (3580 B/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package iputils-ping.
(Reading database ... 7545 files and directories currently installed.)
Unpacking iputils-ping (from .../iputils-ping_3%3a20101006-1ubuntu1_amd64.deb) ...
Setting up iputils-ping (3:20101006-1ubuntu1) ...
root@87370a9b56b0:/# ping www.baidu.com
PING www.a.shifen.com (115.239.211.112) 56(84) bytes of data.
64 bytes from 115.239.211.112: icmp_req=1 ttl=47 time=35.8 ms
64 bytes from 115.239.211.112: icmp_req=2 ttl=47 time=35.8 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 35.816/35.822/35.828/0.006 ms
保存修改后的容器为新镜像
先退出容器
root@87370a9b56b0:/# exit
exit
[root@centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
87370a9b56b0 docker.io/learn/tutorial "/bin/bash" About an hour ago Up About an hour tutorial
保存修改后容器为镜像
[root@centos ~]# docker commit 87370a9b56b0 registry.cn-hangzhou.aliyuncs.com/wzgdxg/newimage:1.0.0
sha256:209e769fa98794f7e265fde0dcb78af78dda3abf01ffb0bb1e3dd7d3e248a4d6
[root@centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/wzgdxg/newimage 1.0.0 209e769fa987 3 seconds ago 152.8 MB
registry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox 1.0.0 14889344ccaa About a minute ago 152.8 MB
docker.io/busybox latest e02e811dd08f 5 weeks ago 1.093 MB
docker.io/learn/tutorial latest a7876479f1aa 3 years ago 128 MB
新的newimage镜像被保存出来了,我们验证newimage是否包含刚装的ping,先删除已经启动的容器,在启动newimage。
[root@centos ~]# docker stop 87370a9b56b0
87370a9b56b0
[root@centos ~]# docker rm 87370a9b56b0
87370a9b56b0
[root@centos ~]# docker run -d -it --name=newimage registry.cn-hangzhou.aliyuncs.com/wzgdxg/newimage:1.0.0 /bin/bash
f156289920964f3e9ce3878f7a7d2714361173ebe1105c423e988dfe2ec97264
[root@centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f15628992096 registry.cn-hangzhou.aliyuncs.com/wzgdxg/newimage:1.0.0 "/bin/bash" 3 seconds ago Up 3 seconds newimage
进入容器验证下
[root@centos ~]# docker exec -it newimage bash
root@f15628992096:/# ping www.baidu.com
PING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.
64 bytes from 115.239.210.27: icmp_req=1 ttl=47 time=47.3 ms
64 bytes from 115.239.210.27: icmp_req=2 ttl=47 time=47.0 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 47.019/47.188/47.358/0.275 ms
我们再把newimage推送到阿里云仓库
[root@centos ~]# docker push registry.cn-hangzhou.aliyuncs.com/wzgdxg/newimage:1.0.0
The push refers to a repository [registry.cn-hangzhou.aliyuncs.com/wzgdxg/newimage]
91466e7b50f0: Pushed
ee1ba0cc9b81: Pushed
1.0.0: digest: sha256:cdcd535beb974a7304c39f19b11bf21f6211441eea65ca445f170b07700bc0ec size: 718
docker入门(二)的更多相关文章
- docker入门(二)容器与镜像的理解
10张图带你深入理解Docker容器和镜像 申明:此篇文章是转载的(原文地址http://dockone.io/article/783),今天意外发现已经有人转载了(复制了),希望大家关注原创 原本打 ...
- docker入门(二)容器与镜像的关系
[编者的话]本文用图文并茂的方式介绍了容器.镜像的区别和Docker每个命令后面的技术细节,能够很好的帮助读者深入理解Docker. 这篇文章希望能够帮助读者深入理解Docker的命令,还有容器(co ...
- Docker入门二
容器管理 1.docker create创建一个容器,但容器并没启动,就和我们创建虚拟机一样,创建了虚拟机后没启动 [root@centos-02 ~]# docker create -it cent ...
- Docker入门教程(二)命令
Docker入门教程(二)命令 [编者的话]DockerOne组织翻译了Flux7的Docker入门教程,本文是系列入门教程的第二篇,介绍了Docker的基本命令以及命令的用法和功能. 在Docker ...
- 【实战】Docker入门实践二:Docker服务基本操作 和 测试Hello World
操作环境 操作系统:CentOS7.2 内存:1GB CPU:2核 Docker服务常用命令 docker服务操作命令如下 service docker start #启动服务 service doc ...
- 【转载】大白话Docker入门(二)
原文:https://yq.aliyun.com/articles/63517?spm=a2c4e.11153940.blogcont63035.15.12011c3fddklk0 上篇的大白话Doc ...
- 二、docker入门
docker入门 使用场景: 面向产品.面向开发.面向测试.面向运维.面向自动化.面向微服务.面向大规模的分布式架构(微信红包) 虚拟化解决方案: 商业解决方案: VMware vSphere,VMw ...
- Docker入门(二):安装/卸载
这个<Docker入门系列>文档,是根据Docker官网(https://docs.docker.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指 ...
- Docker入门
-----------------------------------------Docker入门教程(一)介绍Docker入门教程(二)命令Docker入门教程(三)DockerFileDocker ...
- Docker 入门实践
欢迎大家前往腾讯云技术社区,获取更多腾讯海量技术实践干货哦~ 作者:张戈 导语 本文从新手视角记录了一个实际的Dokcer应用场景从创建.上传直到部署的详细过程,并简单的介绍了腾讯云容器服务的使用方法 ...
随机推荐
- js获取返回首页
<script>setTimeout(function(){ window.location.href="http://"+window.location.hos ...
- 百度编辑器ueditor如何配置
完全版: 1.加载 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" ...
- hadoop2.2.0 单机伪分布式(含64位hadoop编译) 及 eclipse hadoop开发环境搭建
hadoop中文镜像地址:http://mirrors.hust.edu.cn/apache/hadoop/core/hadoop-2.2.0/ 第一步,下载 wget 'http://archive ...
- 均值,方差: 概率质量函数PMF
__author__ = 'dell' import Pmf import matplotlib.pyplot as pyplot pmf = Pmf.MakePmfFromList([1, 2, 2 ...
- 修改weblogic jvm启动参数
进入: D:\Oracle\Middleware\user_projects\domains\base_domain\startWebLogic.cmd 在call 上一行增加: set USER_M ...
- web 缓存
http://robbinfan.com/blog/38/orm-cache-sumup http://my.oschina.net/ITBoy/blog/23683 http://www.kuqin ...
- iOS Developer Libray (中文版)-- About Objective-C
该篇是我自己学习iOS开发时阅读文档时随手记下的翻译,有些地方不是很准确,但是意思还是对的,毕竟我英语也不是很好,很多句子无法做到准确的字词翻译,大家可以当做参考,有错误欢迎指出,以后我会尽力翻译的更 ...
- java 实现多种排序
public class Sort { //交换两个数 private void swap(int[] arr, int i,int j){ int temp = a ...
- linux eclipse c++配置
安装cdt: https://www.eclipse.org/cdt/downloads.php 新建一个c++工程,运行发生错误: Eclipse CDT launch failed.Binary ...
- node.js基础模块http、网页分析工具cherrio实现爬虫
node.js基础模块http.网页分析工具cherrio实现爬虫 一.前言 说是爬虫初探,其实并没有用到爬虫相关第三方类库,主要用了node.js基础模块http.网页分析工具cherri ...