当前使用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:
待续
网友评论