docker镜像的导入和导出
启动命令
docker run -d -p 3000:80 twang2218/gitlab-ce-zh:9.0.3
docker run -d -p 8080:80 gitlab/gitlab-ce:latest
将容器修改提交到镜像
# 进入容器内部
[root@#localhost docker]# docker run -ti ubuntu:14.04 /bin/bash
root@812a997f614a:/# id
uid=0(root) gid=0(root) groups=0(root)
#做了一些修改
root@812a997f614a:/# echo update>update.txt
root@812a997f614a:/# exit
exit
[root@#localhost docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
812a997f614a ubuntu:14.04 "/bin/bash" 7 minutes ago Exited (0) 22 seconds ago zealous_euler
69304dea46c7 gitlab/gitlab-ce:latest "/assets/wrapper" About an hour ago Exited (127) 44 minutes ago competent_minsky
67ba866e21b0 gitlab/gitlab-ce:latest "/assets/wrapper" 2 hours ago Exited (137) About an hour ago hungry_hoover
2a3d08a0a2ff twang2218/gitlab-ce-zh:9.0.3 "/assets/wrapper" 2 hours ago Exited (137) About an hour ago nervous_wozniak
6db49540be99 twang2218/gitlab-ce-zh:9.0.3 "/assets/wrapper" 2 hours ago Exited (255) 2 hours ago 22/tcp, 443/tcp, 0.0.0.0:3000->80/tcp romantic_elion
b08a6d6ed716 gitlab/gitlab-ce:latest "/assets/wrapper" 2 hours ago Exited (255) 2 hours ago 22/tcp, 443/tcp, 0.0.0.0:8080->80/tcp competent_brahmagupta
33fd0b1ebd27 gitlab/gitlab-ce:latest "/assets/wrapper" 2 hours ago Exited (127) 2 hours ago loving_brattain
6f53620a930c twang2218/gitlab-ce-zh:9.0.3 "/assets/wrapper" 3 hours ago Exited (127) 2 hours ago brave_galileo
88df78f77c4e ubuntu:14.04 "sleep 360" 4 days ago Exited (137) 4 days ago testcopy
81a879a36bd3 wordpress "docker-entrypoint..." 4 days ago Exited (0) 4 days ago wordpress
a57a3cc492b7 mysql "docker-entrypoint..." 4 days ago Exited (0) 4 days ago mysqlwp
# 将修改多的镜像保存成一个新的
[root@#localhost docker]# docker commit 812a997f614a ubuntu:update
sha256:317f102584605694da424bc96764559a1ccfda13943353f4cbdfd89c96515e6b
[root@#localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu update 317f10258460 5 seconds ago 188 MB
twang2218/gitlab-ce-zh 9.0.3 36172b5fefab 44 hours ago 1.19 GB
gitlab/gitlab-ce latest 5eff2e44957c 2 days ago 1.11 GB
mysql latest 9546ca122d3a 8 days ago 407 MB
wordpress latest 4ad41adc2794 2 weeks ago 401 MB
ubuntu 14.04 7c09e61e9035 5 weeks ago 188 MB
daocloud.io/library/nginx 1.7.1 e3e043d3ed2f 2 years ago 499 MB
# 查看修改多的镜像和原来镜像之间的差异
[root@#localhost docker]# docker diff 812a997f614a
C /var
C /var/cache
C /var/cache/apt
D /var/cache/apt/srcpkgcache.bin
D /var/cache/apt/pkgcache.bin
C /var/lib
C /var/lib/apt
C /var/lib/apt/lists
A /var/lib/apt/lists/lock
A /var/lib/apt/lists/partial
A /var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_trusty-updates_InRelease
A /update.txt
C /root
A /root/.bash_history
[root@#localhost docker]#
镜像的导入和导出
export 和improt
[root@#localhost docker]# docker run -ti ubuntu:update /bin/bash
root@cbe3cb7799ed:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp update.txt usr var
[root@#localhost docker]#
[root@#localhost docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cbe3cb7799ed ubuntu:update "/bin/bash" 47 seconds ago Exited (1) 6 seconds ago adoring_kare
812a997f614a ubuntu:14.04 "/bin/bash" 16 minutes ago Exited (0) 8 minutes ago zealous_euler
69304dea46c7 gitlab/gitlab-ce:latest "/assets/wrapper" 2 hours ago Exited (127) 53 minutes ago competent_minsky
67ba866e21b0 gitlab/gitlab-ce:latest "/assets/wrapper" 2 hours ago Exited (137) 2 hours ago hungry_hoover
2a3d08a0a2ff twang2218/gitlab-ce-zh:9.0.3 "/assets/wrapper" 2 hours ago Exited (137) 2 hours ago nervous_wozniak
6db49540be99 twang2218/gitlab-ce-zh:9.0.3 "/assets/wrapper" 2 hours ago Exited (255) 2 hours ago 22/tcp, 443/tcp, 0.0.0.0:3000->80/tcp romantic_elion
b08a6d6ed716 gitlab/gitlab-ce:latest "/assets/wrapper" 2 hours ago Exited (255) 2 hours ago 22/tcp, 443/tcp, 0.0.0.0:8080->80/tcp competent_brahmagupta
33fd0b1ebd27 gitlab/gitlab-ce:latest "/assets/wrapper" 3 hours ago Exited (127) 2 hours ago loving_brattain
6f53620a930c twang2218/gitlab-ce-zh:9.0.3 "/assets/wrapper" 3 hours ago Exited (127) 2 hours ago brave_galileo
88df78f77c4e ubuntu:14.04 "sleep 360" 4 days ago Exited (137) 4 days ago testcopy
81a879a36bd3 wordpress "docker-entrypoint..." 4 days ago Exited (0) 4 days ago wordpress
a57a3cc492b7 mysql "docker-entrypoint..." 4 days ago Exited (0) 4 days ago mysqlwp
# 将镜像导出到文件
[root@#localhost docker]# docker export cbe3cb7799ed > update.tar
# 创建一个新静像从基于导出的文件
[root@#localhost /]# docker import - update < update.tar
sha256:fd00d520a43eb5dc6cca8717fe0ca04cfdc53b02cad2fb5b50d877b8e6d6c3bc
[root@#localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
update latest fd00d520a43e 13 seconds ago 165 MB
ubuntu update 317f10258460 11 minutes ago 188 MB
twang2218/gitlab-ce-zh 9.0.3 36172b5fefab 44 hours ago 1.19 GB
gitlab/gitlab-ce latest 5eff2e44957c 2 days ago 1.11 GB
mysql latest 9546ca122d3a 8 days ago 407 MB
wordpress latest 4ad41adc2794 2 weeks ago 401 MB
ubuntu 14.04 7c09e61e9035 5 weeks ago 188 MB
daocloud.io/library/nginx 1.7.1 e3e043d3ed2f 2 years ago 499 MB
[root@#localhost /]#
save 和load
(像当与镜像的备份和恢复)
# update是一个已经存在的镜像
[root@#localhost /]# docker save -o update1.tar update
[root@#localhost /]# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp update1.tar update.tar usr var
[root@#localhost /]# du -sh update1.tar
166M update1.tar
# 删除update镜像
[root@#localhost /]# docker rmi update
Untagged: update:latest
Deleted: sha256:fd00d520a43eb5dc6cca8717fe0ca04cfdc53b02cad2fb5b50d877b8e6d6c3bc
Deleted: sha256:14cc8cd7b783152682835346e5fe90860a9feeb684866688692285319d4e97ad
[root@#localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu update 317f10258460 16 minutes ago 188 MB
twang2218/gitlab-ce-zh 9.0.3 36172b5fefab 44 hours ago 1.19 GB
gitlab/gitlab-ce latest 5eff2e44957c 2 days ago 1.11 GB
mysql latest 9546ca122d3a 8 days ago 407 MB
wordpress latest 4ad41adc2794 2 weeks ago 401 MB
ubuntu 14.04 7c09e61e9035 5 weeks ago 188 MB
daocloud.io/library/nginx 1.7.1 e3e043d3ed2f 2 years ago 499 MB
#导入镜像
[root@#localhost /]# docker load < update1.tar
14cc8cd7b783: Loading layer [==================================================>] 173.8 MB/173.8 MB
Loaded image: update:latest
[root@#localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
update latest fd00d520a43e 6 minutes ago 165 MB
ubuntu update 317f10258460 17 minutes ago 188 MB
twang2218/gitlab-ce-zh 9.0.3 36172b5fefab 44 hours ago 1.19 GB
gitlab/gitlab-ce latest 5eff2e44957c 2 days ago 1.11 GB
mysql latest 9546ca122d3a 8 days ago 407 MB
wordpress latest 4ad41adc2794 2 weeks ago 401 MB
ubuntu 14.04 7c09e61e9035 5 weeks ago 188 MB
daocloud.io/library/nginx 1.7.1 e3e043d3ed2f 2 years ago 499 MB
[root@#localhost /]#
Dockerfile
[root@#localhost ~]# mkdir docker_file
[root@#localhost ~]# cd docker_file/
[root@#localhost docker_file]# vi Dockerfile
[root@#localhost docker_file]# cat Dockerfile
FROM ubuntu:14.04
ENTRYPOINT ["/bin/echo"]
[root@#localhost docker_file]# docker build .
Sending build context to Docker daemon 2.048 kB
Step 1/2 : FROM ubuntu:14.04
---> 7c09e61e9035
Step 2/2 : ENTRYPOINT /bin/echo
---> Running in d53f31b93355
---> 26dd06d2e5a5
Removing intermediate container d53f31b93355
Successfully built 26dd06d2e5a5
#运行镜像
[root@#localhost docker_file]# docker run 26dd06d2e5a5
#加入一个参数
[root@#localhost docker_file]# docker run 26dd06d2e5a5 hello world
hello world
[root@#localhost docker_file]# vi Dockerfile
[root@#localhost docker_file]# docker run 26dd06d2e5a5 hello world
hello world
#
[root@#localhost docker_file]# cat Dockerfile
FROM ubuntu:14.04
#ENTRYPOINT ["/bin/echo","Hi world!"]
CMD ["/bin/echo","Hi world!"]
[root@#localhost docker_file]# docker build .
[root@#localhost docker_file]# docker run 12458a717ced
Hi world!
[root@#localhost docker_file]# docker run 12458a717ced /bin/date
Sat Apr 8 12:08:14 UTC 2017
构建的时候打个标签
[root@#localhost docker_file]# docker build -t yang:01 .
Sending build context to Docker daemon 3.584 kB
Step 1/2 : FROM ubuntu:14.04
---> 7c09e61e9035
Step 2/2 : CMD /bin/echo Hi world!
---> Running in 94e510f085d7
---> 6b33c8a6a32f
Removing intermediate container 94e510f085d7
Successfully built 6b33c8a6a32f
[root@#localhost docker_file]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
yang 01 6b33c8a6a32f 5 seconds ago 188 MB
update latest fd00d520a43e 29 minutes ago 165 MB
ubuntu update 317f10258460 41 minutes ago 188 MB
twang2218/gitlab-ce-zh 9.0.3 36172b5fefab 44 hours ago 1.19 GB
gitlab/gitlab-ce latest 5eff2e44957c 2 days ago 1.11 GB
mysql latest 9546ca122d3a 8 days ago 407 MB
wordpress latest 4ad41adc2794 2 weeks ago 401 MB
ubuntu 14.04 7c09e61e9035 5 weeks ago 188 MB
daocloud.io/library/nginx 1.7.1 e3e043d3ed2f 2 years ago 499 MB
[root@#localhost docker_file]#
构建实例
将flask应用 打包的镜像中
编写python程序 hellp.py
#!/usr/bin/env python
from flask import Flask
app = Flask(__name__)
@app.route('/hi')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
编写Dockerfile
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y python
RUN apt-get install -y python-pip
RUN apt-get clean all
RUN pip install flask
ADD hello.py /tmp/hello.py
EXPOSE 5000
CMD ["python","/tmp/hello.py"]
docker镜像的导入和导出的更多相关文章
- Docker 镜像的导入和导出
镜像的导入和导出 export 和improt [root@#localhost docker]# docker run -ti ubuntu:update /bin/bash root@cbe3cb ...
- kubernetes集群搭建(9):docker 镜像的导入与导出
由于K8s搭建时官方提供的镜像不FQ是访问不了的,所以搭建过程中很多时间都耗费在去找镜像去了 下面是我搭建k8s集群用到的镜像 没有采用之前我用的二进制文件搭建(dns没成功),这里采用的Kubea ...
- docker镜像文件导入与导出
工作中经常需要拉取一些国外的镜像,但是网络限制等原因在公司拉取很慢,所以我习惯用亚马逊服务器拉取镜像,导出后下载到本地再导入开发环境 1. 查看镜像id sudo docker images REPO ...
- docker镜像文件导入与导出,支持批量
工作中经常需要拉取一些国外的镜像,但是网络限制等原因在公司拉取很慢,所以我习惯用亚马逊服务器拉取镜像,导出后下载到本地再导入开发环境 1. 查看镜像id sudo docker images REPO ...
- docker镜像文件导入与导出 , 支持批量
1. 查看镜像id sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE quay.io/calico/node v1.0.1 c70511a ...
- Docker 镜像-管理-导入-导出
目录 Docker 镜像基本概念 Docker 镜像加速 Docker 镜像 常用命令 Docker 镜像的创建和导出导入 Docker 镜像基本概念 我们使用的容器都是基于镜像的,镜像是由多层组成的 ...
- docker镜像和容器的导出导入
本文介绍docker镜像和容器的导入导出,用于迁移.备份.升级等场景.主要用到export.import.save.load四个方法. 原文地址:代码汇个人博客 http://www.codehui. ...
- docker容器和镜像的导入和导出
镜像的保存 [root@wxtest1607 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat8 3.0 90457edaf6 ...
- docker 镜像的导入导出
今天使用docker部署asp.net core应用程序时,发现当我们做好基础镜像之后需要把镜像导出到正式环境,因此学习了一下如何从docker中导出镜像: 1.首先通过docker images命令 ...
随机推荐
- python中类(class)和实例(instance)
面向对象最重要的概念就是类(Class)和实例(Instance),必须牢记类是抽象的模板,比如Student类,而实例是根据类创建出来的一个个具体的“对象”,每个对象都拥有相同的方法,但各自的数据可 ...
- 结合canvas做雨滴特效
雨滴特效 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...
- IIS部署PHP项目并与mysql完美结合
在上一篇文章中,提到iis与apache共用80端口,但是发现很多问题,例如 IIS网站有支付功能,而微信支付是不支持带有端口的网址的,虽然通过apche代理,在外面看来没有端口,可是内部还是避免不了 ...
- pd.read_csv的header用法
默认Header = 0: In [3]: import pandas as pd In [4]: t_user = pd.read_csv(r'C:\Users\Song\Desktop\jdd_d ...
- C++11 里lambda表达式的学习
最近看到很多关于C++11的文档,有些是我不怎么用到,所以就略过去了,但是lambda表达式还是比较常用的,其实最开始学习python的时候就觉得lambda这个比较高级,为什么C++这么弱.果然C+ ...
- 算法总结之 构造数组MaxTree
一个数组的MaxTree定义如下: 数组必须没有重复元素 MaxTree是一颗二叉树,数组的每一个值对应一个二叉树的节点 包括MaxTre树在内且在其中的每一颗子树上,值最大的节点都是树的头 给定一个 ...
- linux jdk安装。
我使用的centos 7: 安转sun公司的jdk要先检查系统中是否安装jdk,一般来说Centos系统会默认会安装OpenJDK,但是openJDK部分内容 与SUN JDK不兼容,因此下面进行重新 ...
- vc 判断当前用户是否在管理员组以及是否SYSTEM权限运行
BOOL IsUserInAdminGroup() //判断是否在管理员组 { BOOL fInAdminGroup = FALSE; HANDLE hToken = NULL; HANDLE hTo ...
- QT QMimeData类
http://blog.csdn.net/xie376450483/article/details/5863810 QMimeData类提为数据提供一个容器,用来记录关于MIME类型数据的信息 QMi ...
- 安装Linux应该知道的十件事
硬件,软件及其之间的一切 Linux机器的硬件和软件之间一切都由内核主宰. 内核负责硬件和软件的连接,每隔几个礼拜就可以在Internet上获取 更新的内核: 如果你自己安装内核并非易事,这时,就轮到 ...