这篇文章说明一个可以在后续进行蓝绿部署、灰度发布以及负载均衡的tornado镜像。
tornado镜像
- 蓝绿部署:https://blog.csdn.net/liumiaocn/article/details/80572373
- 金丝雀发布:https://blog.csdn.net/liumiaocn/article/details/80572672
镜像使用示例如下所示:简单来说就是可以通过参数提供一个标识符,可以与容器进行关联,从而使访问者直到所访问的容器实例是哪一个。
[root@kong ~]# docker run -d -p 7001:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "Hello main service: v1 in 7001"
28f42bbd21146c520b05ff2226514e62445b4cdd5d82f372b3791fdd47cd602a
[root@kong ~]# docker run -d -p 7002:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "Hello canary deploy service: v2 in 7002"
b86c4b83048d782fadc3edbacc19b73af20dc87f5f4cf37cf348d17c45f0215d
[root@kong ~]# curl http://192.168.163.117:7001
Hello, Service :Hello main service: v1 in 7001
[root@kong ~]# curl http://192.168.163.117:7002
Hello, Service :Hello canary deploy service: v2 in 7002
[root@kong ~]#
这里将tornado这个用作HelloWorld的示例镜像继续简单修改一下,使得端口号不再缺省使用8080,可以通过参数指定,同时显示信息中直接使用python获取了hostname进行输出,可以更为方便的确认容器的状况,尤其是在有自愈能力的Kubernetes集群中,容器可能由于意外退出已经不再是之前的那个容器了,通过这个都能反映出来。
镜像下载
[root@host131 ~]# docker pull liumiaocn/tornado:greeting
greeting: Pulling from liumiaocn/tornado
c9b1b535fdd9: Pull complete
400dcd8f01fa: Pull complete
5b26d9e7d0ea: Pull complete
Digest: sha256:730baadb597c13380c6d353128ff7baa29aff925b11f5bdaeace29110ef68dca
Status: Downloaded newer image for liumiaocn/tornado:greeting
docker.io/liumiaocn/tornado:greeting
[root@host131 ~]#
之前的liumiaocn/tornado:latest可继续使用,不受影响,后续也不会再修改此latest的镜像,因为已经有一些文章示例是使用latest的tag了。
使用方式
- 启动容器
[root@host131 ~]# docker run -d -p 7001:80 --name=greetings liumiaocn/tornado:greeting python /usr/local/bin/daemon-greeting.py "Welcome to use tornado for greetings" 80
1ad17e8a06e463b8302b4f4883c699ca3c2b543f006504358718554239df609c
[root@host131 ~]#
- 确认结果
[root@host131 ~]# curl http://localhost:7001
Host Name: 1ad17e8a06e4 : Welcome to use tornado for greetings
[root@host131 ~]#
- 确认hostname
root@host131 ~]# docker exec greetings hostname
1ad17e8a06e4
[root@host131 ~]#