docker镜像的导入和导出的实现

gitlab 的docker使用

gitlab 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镜像导入导出内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • Docker镜像导出与导入与拷贝实例分析

    第一种解决方案是,将镜像推送到公有的镜像仓库,然后pull下来 第二种,将镜像打包,然后拷贝到第二台服务器中 #将镜像存储 docker save gateway:latest > /home/gateway.tar 将gateway.tar复制到需要的服务器上,然后在服务器上导入该镜像文件 #导入镜像文件 docker load --input /root/docker-images/nginx.tar 或者通过符号的方式来导入 docker load < /root/docker-imag

  • 在 docker 之间导出导入镜像的方法

    很喜欢玩docker,但最新遇到一个问题,公司给的新机器的dns有问题,导致pull不下来镜像. 没办法了,没有镜像什么神马都干不了,又不能花很多时间去搭建私有的镜像库,只有另寻办法了. 废话少说,经过探究,发现 docker 提供把镜像导出export(保存save)为文件的机制,这样就可以把镜像copy到任意地方了. 1. 导出 export - 导入 import 格式:docker export CONTAINER(容器) 使用 docker ps -a 查看本机已有的容器,如: 我们使

  • Docker镜像的导入导出的实现方法

    本文介绍Docker镜像的导入导出,用于迁移.备份.升级等场景,准备环境如下: CentOS 7.0 Docker 1.18 导入导出命令介绍 涉及的命令有export.import.save.load save 命令 docker save [options] images [images...] 示例 docker save -o nginx.tar nginx:latest 或 docker save > nginx.tar nginx:latest 其中-o和>表示输出到文件,ngin

  • docker镜像导入导出备份迁移的操作

    导出: docker save -o centos.tar centos:latest #将centos:latest镜像导出为centos.tar文件 导入: docker load -i centos.tar #加载centos.tar,加载后的镜像各标签与原导出的镜像标签相同 补充知识:docker将镜像保存为tar文件 将单个文件保存为tar文件,并加载到本地 docker save ****.v1 > images.tar docker load < images.tar 将多个文件

  • docker镜像的导入和导出的实现

    gitlab 的docker使用 gitlab 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

  • Docker镜像的导入导出代码实例

    Docker镜像的导入导出 本文介绍Docker镜像的导入导出,用于迁移.备份.升级等场景,准备环境如下: CentOS 7.0 Docker 1.18 导入导出命令介绍 涉及的命令有export.import.save.load save 命令 docker save [options] images [images...] 示例 docker save -o nginx.tar nginx:latest 或 docker save > nginx.tar nginx:latest 其中-o和

  • Docker镜像与容器的导入导出操作实践

    目录 一.前言 二.docker镜像的导入和导出 1.docker镜像的导出 2.docker镜像的导入 三.docker容器的导入和导出 1.docker容器的导出 2.docker容器的导入 四.总结 一.前言 随着容器技术的发展,现在很多的应用程序系统都会选择使用docker容器进行部署,但是有时候使用docker容器进行部署的时候会遇到问题,比如说我们的应用程序里面需要依赖其他第三方的镜像,如果这时候服务器是在内网不能连接外网的情况下,那么就无法部署了.基于这种情况,docker官方支持

  • Docker 镜像导入导出过程介绍

    docker save 说明:将指定镜像保存成 tar 归档文件,以tar和tar.gz结尾都行. 语法: docker save [OPTIONS] IMAGE [IMAGE...] OPTIONS 说明: -o :输出到的文件. [root@harbor tmp]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE redis v1 cc6cf492f595 6 hours ago 113MB busybox latest beae173c

  • Docker镜像与容器的导入导出以及常用命令总结

    目录 前言 一.Docker 镜像和容器的导入导出 1.1.镜像的导入导出 1.1.1.镜像的保存 1.1.2.镜像的导入 1.2.容器的导入和导出 1.2.1.容器的导出 1.2.2.容器包的导入 二.Docker 常用命令 总结 前言 大家好,本文是对 Docker 的镜像和容器的一些操作指令的汇总,比如镜像和容器的导入导出,以及一些在使用过程中的常用命令.希望对大家有所帮助~ 一.Docker 镜像和容器的导入导出 1.1.镜像的导入导出 1.1.1.镜像的保存 通过镜像ID保存 方式一:

  • docker实践之容器的导入与导出

    前言 Docker的流行与它对容器的易分享和易移植密不可分.用户不仅可以把容器提交到公共服务器上,还可以将容器导出到本地文件系统中.同样,我们也可以将导出的容器重新导入到Docker环境中去. 如果要导出本地某个容器,可以使用 Docker export 命令,可以使用 docker import 从容器快照文件中再导入为镜像 1.首先查找正在运行的容器ID 2.然后使用 docker export 命令将容器导出(这里以GWAS_HF容器为例) 3.查看导出结果,scp命令传输到另一台服务器

  • Docker容器的导入导出操作教程

    背景 Docker的流行与它对容器的易分享和易移植密不可分,用户不仅可以把容器提交到公共服务器上,还可以把容器导出到本地文件系统中.同样,我们也可以把导出的容器重新导入到Docker运行环境中. 方法1:容器的导入与导出(export和import) 1.查看需要导出的容器 docker ps -a 2.导出export 导出后的tar文件传输至待导入机器上 docker export 容器名或者容器ID > 导出的路径以及tar包的名字 docker export centos> cento

随机推荐