【ops】使用docker制作senlin镜像文件

当前使用Docker容器技术部署自己的应用以逐渐成为主流,由于senlin项目跟Openstack kilo版本存在基础组件上版本不兼容的问题,所以我们使用Docker来部署senlin服务,在部署服务前,我们需要把senlin服务制作进Docker镜像文件中。常见的docker镜像制作方法有三种:

  • 一、基于已有镜像容器:

    • 1.查找原始镜像:
eldon@ubuntu:~/git$ sudo docker search centos
NAME                                   DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                                 The official build of CentOS.                   2965      [OK]
jdeathe/centos-ssh                     CentOS-6 6.8 x86_64 / CentOS-7 7.3.1611 x8...   54                   [OK]
nimmis/java-centos                     This is docker images of CentOS 7 with dif...   20                   [OK]
gluster/gluster-centos                 Official GlusterFS Image [ CentOS-7 +  Glu...   15                   [OK]
million12/centos-supervisor            Base CentOS-7 with supervisord launcher, h...   12                   [OK]
torusware/speedus-centos               Always updated official CentOS docker imag...   8                    [OK]
egyptianbman/docker-centos-nginx-php   A simple and highly configurable docker co...   6                    [OK]
nathonfowlie/centos-jre                Latest CentOS image with the JRE pre-insta...   5                    [OK]
centos/mariadb55-centos7                                                               3                    [OK]
harisekhon/centos-java                 Java on CentOS (OpenJDK, tags jre/jdk7-8)       2                    [OK]
sgfinans/docker-centos                 CentOS with a running sshd and Docker           1                    [OK]
harisekhon/centos-scala                Scala + CentOS (OpenJDK tags 2.10-jre7 - 2...   1                    [OK]
darksheer/centos                       Base Centos Image -- Updated hourly             1                    [OK]
blacklabelops/centos                   CentOS Base Image! Built and Updates Daily!     1                    [OK]
timhughes/centos                       Centos with systemd installed and running       1                    [OK]
vcatechnology/centos                   A CentOS Image which is updated daily           0                    [OK]
grayzone/centos                        auto build for centos.                          0                    [OK]
ustclug/centos                          USTC centos                                    0                    [OK]
grossws/centos                         CentOS 6 and 7 base images with gosu and l...   0                    [OK]
smartentry/centos                      centos with smartentry                          0                    [OK]
kz8s/centos                            Official CentOS plus epel-release               0                    [OK]
januswel/centos                        yum update-ed CentOS image                      0                    [OK]
aguamala/centos                        CentOS base image                               0                    [OK]
harisekhon/centos-github               CentOS latest with all my GitHub repos pre...   0                    [OK]
repositoryjp/centos                    Docker Image for CentOS.                        0                    [OK]
  • 2.下载原始镜像:
eldon@ubuntu:~/git$ sudo docker pull centos
Using default tag: latest
latest: Pulling from library/centos
45a2e645736c: Pull complete
Digest: sha256:c577af3197aacedf79c5a204cd7f493c8e07ffbce7f88f7600bf19c688c38799
Status: Downloaded newer image for centos:latest
  • 3.查看本地镜像:
eldon@ubuntu:~/git$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              67591570dd29        2 weeks ago         191.8 MB
  • 4.启动镜像:
eldon@ubuntu:~/git$ sudo docker run -ti 67591570dd29 /bin/bash
[root@aa06369be822 /]#
  • 5.在容器中部署应用:
[root@aa06369be822 /]# ls
anaconda-post.log  bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@aa06369be822 /]# cd home/
[root@aa06369be822 home]# yum update
[root@aa06369be822 home]# yum install -y git
[root@aa06369be822 home]# git clone http://git.openstack.org/openstack/senlin.git
[root@aa06369be822 home]# curl -O https://bootstrap.pypa.io/get-pip.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1558k  100 1558k    0     0   741k      0  0:00:02  0:00:02 --:--:--  741k
[root@aa06369be822 home]# ls
get-pip.py  senlin
[root@aa06369be822 home]# python get-pip.py
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |################################| 1.3MB 219kB/s
Collecting setuptools
  Downloading setuptools-32.3.1-py2.py3-none-any.whl (479kB)
    100% |################################| 481kB 1.4MB/s
Collecting wheel
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
    100% |################################| 71kB 4.5MB/s
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-9.0.1 setuptools-32.3.1 wheel-0.29.0
[root@aa06369be822 home]# cd senlin
[root@aa06369be822 senlin]# yum install gcc
[root@aa06369be822 senlin]# yum install python-devel.x86_64
[root@aa06369be822 senlin]# pip install -e .
[root@aa06369be822 senlin]# cd ..
[root@aa06369be822 home]# git clone http://git.openstack.org/openstack/python-senlinclient.git
[root@aa06369be822 home]# cd python-senlinclient/
[root@aa06369be822 python-senlinclient]# python setup.py install
[root@aa06369be822 python-senlinclient]# yum install -y sudo which
[root@aa06369be822 python-senlinclient]# yum clean all
Loaded plugins: fastestmirror, ovl
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@aa06369be822 python-senlinclient]# chown -R senlin:senlin /etc/senlin/ /var/log/senlin/ /var/cache/senlin/
[root@aa06369be822 python-senlinclient]# cd .. && git clone https://github.com/openstack/python-openstacksdk.git
[root@aa06369be822 python-senlinclient]# pip install pymysql
[root@aa06369be822 home]# cd python-openstacksdk/ && pip install -e .
  • 6.退出容器:
[root@aa06369be822 senlin]# exit
exit
  • 7.查看容器id:
eldon@ubuntu:~/git$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
aa06369be822        67591570dd29        "/bin/bash"         49 minutes ago      Exited (0) 30 seconds ago                       modest_lamport
  • 8.基于容器id提交新的镜像:
eldon@ubuntu:~/git$ sudo docker help commit
Usage:  docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Create a new image from a container's changes
Options:
  -a, --author string    Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  -c, --change value     Apply Dockerfile instruction to the created image (default [])
      --help             Print usage
  -m, --message string   Commit message
  -p, --pause            Pause container during commit (default true)
eldon@ubuntu:~/git$ sudo docker commit -a "EldonZhao" aa06369be822 centos-senlin:latest
sha256:c467749df34d7d582340222d7d1f2ee8f4f4130049eed8ab6beded495d450412
  • 9.查看本地镜像:
eldon@ubuntu:~/git$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos-senlin       latest              c467749df34d        37 seconds ago      481.5 MB
centos              latest              67591570dd29        2 weeks ago         191.8 MB
  • 10.存出镜像:
eldon@ubuntu:~/git$ sudo docker help save
Usage:  docker save [OPTIONS] IMAGE [IMAGE...]
Save one or more images to a tar archive (streamed to STDOUT by default)
Options:
      --help            Print usage
  -o, --output string   Write to a file, instead of STDOUT
eldon@ubuntu:~/git$ sudo docker save -o centos-senlin.img centos-senlin:latest
eldon@ubuntu:~/git$ ls
centos-senlin.img

至此,基于已有容器镜像制作镜像的步骤全部完成,在存出的目标路径下就可以看到制作好的镜像文件。

  • 二、基于本地模板:

待续

  • 三、基于Dockerfile:

待续

参考资料

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,390评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,821评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,632评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,170评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,033评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,098评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,511评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,204评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,479评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,572评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,341评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,213评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,576评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,893评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,171评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,486评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,676评论 2 335

推荐阅读更多精彩内容