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应用场景从创建.上传直到部署的详细过程,并简单的介绍了腾讯云容器服务的使用方法 ...
随机推荐
- jQuery--效果和遍历
七.jQuery效果 (1)jQuery隐藏和显示 //隐藏 $("#hide").click(function(){ $("p").hide(1000); } ...
- PHP 关于MongoDB的操作
<?php header("Content-type:text/html;charset=utf-8"); $m = new MongoClient(); // 连接 $db ...
- Asp.Net使用异步性能就提升吗
Asp.Net异步编程 随着.Net4.5的推出,一种新的编程方式简化了异步编程,在网上时不时的也看到各种打着Asp.Net异步编程的口号,如何提高性能,如何提高吞吐率! 好多文章都说得不清楚,甚 ...
- C#面试-关于const和readonly(看了一个点赞很多的帖子有感而发!)
前景提要: 最近大家都在面试,讨论最多.最基础的问题,莫过于“关于const和readonly常见的笔试题剖析”,等等的大牛解析.我就是一个小菜,只不过,有点不敢苟同大牛的意见.废话少说,进入重点. ...
- C#窗体程序画倾斜一定角度的椭圆
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- House of hello恶搞凯莉迷你包
欧洲站 House of hello恶搞凯莉迷你包 最近淘宝卖的很疯,看看价格,俺咂舌不已 :1300-1600 今年迷你包卖的很疯我是知道的,迷你包今年没有买一个也是不行的! 剔除暴利,便宜的亲们不 ...
- 常见的三种Web服务架构
常见的三种Web服务架构 转自http://www.cnblogs.com/bvbook/archive/2008/12/24/1360942.html 相互竞争的服务架构 The Competing ...
- MVC---Case 1
<!DOCTYPE html> <html lang="en"> <head> <title>Backbone.js, Requir ...
- 【HDOJ】3329 The Flood
超简单BFS. /* 3329 */ #include <iostream> #include <queue> #include <cstdio> #include ...
- Git skills in reseting files
How to uncommit files that were committed long time a ago?Note: Since all changes in the current wor ...