1. 编写Dockerfile文件使用最新的Alpine镜像并安装Python3环境,如下:

    因为python高于3.4则不会默认安装pip,需要手动安装。

    试了很多其他办法都没安装上,唯有下载get-pip.py进行安装。

    这里说一下cherrypy版本不能高于9.0.0,负责等下import wsgiserver会出错,因为wsgiserver后面移出cherrypy了。
FROM alpine
RUN mkdir /install
COPY get-pip.py /install
RUN apk update
RUN apk add bash
RUN apk add python3
RUN python3 /install/get-pip.py
RUN pip install bottle
#RUN pip3 install cherrypy
RUN pip3 install "cherrypy>=3.0.8,<9.0.0"
ADD server.py /root/server.py
EXPOSE 8080:8080
CMD /usr/bin/python3 /root/server.py
  1. 在Dockerfile文件目录下执行下面命令可以创建基于python3的镜像:
$ docker build -t test_python38_http .





  1. 这样基于alpine的python3镜像创建成功了,用下面命令可以查看:
$ docker images

  1. 镜像创建成功后输入命令则可以启动镜像服务了
$ docker run -p 8080:8080 -it test_python38_http

  1. 最后打开浏览器,输入url测试:
http://192.168.99.100:8080/HTTP_SET_COOKIE_LIST_3

关于这个IP也是一个坑,大家可以在启动Docker时看到一个default IP,并不是其他的哦。

  1. 最后贴上http代码
import bottle
from bottle import post, get, delete, route, request
from cherrypy import wsgiserver
import time
import signal @route('/HTTP_SET_COOKIE_LIST_3')
def set_cookie():
print("VA_HTTP HTTP_SET_COOKIE_LIST_3")
count = int( bottle.request.cookies.get('counter', '0') )
count += 1
bottle.response.set_cookie('counter', str(count))
bottle.response.status = 200
bottle.response.content_type = 'text/plain; charset=utf-8'
return "200 HTTP_SET_COOKIE_LIST_3" @route('/HTTP_SET_COOKIE_LIST_4')
def verify_cookie():
count = int( bottle.request.cookies.get('counter', '0') )
if count == 0 :
bottle.response.status = 400
bottle.response.content_type = 'text/plain; charset=utf-8'
return "400 HTTP_SET_COOKIE_LIST_4"
else :
bottle.response.status = 200
bottle.response.content_type = 'text/plain; charset=utf-8'
return "200 HTTP_SET_COOKIE_LIST_4" @route('/<id>')
def HttpRoute_handle(id):
bottle.response.status = 200
bottle.response.content_type = 'text/plain; charset=utf-8'
return "200 "+ id @route('/HTTP_TIMEOUT')
def HttpTime_handle():
time.sleep(30)
bottle.response.status = 200
bottle.response.content_type = 'text/plain; charset=utf-8'
return "200 TIME" #Get for Test HTTP_DO_REQUEST_1, HTTP_SET_POST_DATA_5, HTTP_SET_METHOD_3
@get('/<id>')
def HttpGet_handler(id):
if id == "HTTP_SET_METHOD_3":
bottle.response.status = 200
bottle.response.content_type = 'text/plain; charset=utf-8'
return "200 GET"
elif (id == "HTTP_SET_HEADER_2_0") or (id == "HTTP_SET_HEADER_2_1") or (id == "HTTP_SET_HEADER_2_2"):
if(request.headers.get('FirstHeader') == 'value') and not(request.headers.get('SecondHeader')) and (id == "HTTP_SET_HEADER_2_0"):
bottle.response.status = 200
bottle.response.content_type = 'text/plain; charset=utf-8'
return "200 HTTP_SET_HEADER_2 " + "FirstHeader"
elif (request.headers.get('FirstHeader') == 'value') and (request.headers.get('SecondHeader') == 'value') and (id == "HTTP_SET_HEADER_2_1"):
bottle.response.status = 200
bottle.response.content_type = 'text/plain; charset=utf-8'
return "200 HTTP_SET_HEADER_2 " + "FirstHeader" + "SecondHeader"
elif not(request.headers.get('FirstHeader')) and not(request.headers.get('SecondHeader')) and( id == "HTTP_SET_HEADER_2_2"):
bottle.response.status = 200
bottle.response.content_type = 'text/plain; charset=utf-8'
return "200 HTTP_SET_HEADER_2 "
else:
bottle.response.status = 400
bottle.response.content_type = 'text/plain; charset=utf-8'
return "400 HTTP_SET_HEADER_2"
else:
bottle.response.status = 200
bottle.response.content_type = 'text/plain; charset=utf-8'
return "200 "+ id #Post for Test : HTTP_SET_POST_DATA_3, HTTP_SET_POST_DATA_4, HTTP_SET_POST_DATA_5, HTTP_SET_METHOD_3
@post('/<id>')
def HttpSetPostData_handler(id):
if id == "HTTP_SET_POST_DATA_5" :
bottle.response.status = 400
bottle.response.content_type = 'text/plain; charset=utf-8'
return "400 " + id
elif id == "HTTP_SET_METHOD_3":
Data = bottle.request.forms.get('data')
Cata = bottle.request.forms.get('cata')
if Data:
bottle.response.status = 200
bottle.response.content_type = 'text/plain; charset=utf-8'
return "200 POST " + "data=" + Data
elif Cata:
bottle.response.status = 200
bottle.response.content_type = 'text/plain; charset=utf-8'
return "200 POST " + "cata=" + Cata
else:
bottle.response.status = 400
bottle.response.content_type = 'text/plain; charset=utf-8'
return "400 " + id
else:
testName = bottle.request.forms.get('testname')
if testName == "HTTP_SET_POST_DATA_4":
bottle.response.status = 200
bottle.response.content_type = 'text/plain; charset=utf-8'
return "200 " + id
elif testName == id:
#HTTP_SET_POST_DATA_3
bottle.response.status = 200
bottle.response.content_type = 'text/plain; charset=utf-8'
return "200 " + testName
else :
bottle.response.status = 400
bottle.response.content_type = 'text/plain; charset=utf-8'
return "400 " + id def stop_server(*args, **kwargs):
server.stop() app = bottle.default_app()
server = wsgiserver.CherryPyWSGIServer(("0.0.0.0", 8080), app)
signal.signal(signal.SIGINT, stop_server)
signal.signal(signal.SIGTERM, stop_server)
signal.signal(signal.SIGHUP, stop_server)
print("VA_HTTP TestSuite Server Started")
server.start()

Docker学习笔记:Alpine镜像+Python3安装+http服务器的更多相关文章

  1. Docker学习笔记一 概念、安装、镜像加速

    本文地址:https://www.cnblogs.com/veinyin/p/10406378.html  Docker 是一个容器,可以想象成一个轻便的虚拟机,但不虚拟硬件和操作系统. 优点:启动快 ...

  2. Docker学习笔记【三】安装Redis

    项目中使用到Redis,平常都是别人搭建的,今天试着在Google Cloud Platform 上搭建一个学习环境. 1.使用 docker pull redis 从docker hub中下载镜像 ...

  3. Docker学习笔记:镜像、容器、数据卷

    核心概念 镜像:一个只读的模板,类似虚拟机的镜像. 容器:可以理解为镜像的一个运行实例.运行时类似于沙箱,多个容器互相独立. 仓库:存放镜像文件的地方. 镜像 命令表格 命令 解释 选项 docker ...

  4. Docker学习笔记之镜像与容器

    0x00 概述 镜像和容器作为 Docker 里最基础的概念,我们很有必要了解 Docker 对它们的很多定义以及其他与它们有关的知识.在这一小节里,我们就专门针对镜像与容器两个概念展开,细致的梳理与 ...

  5. docker学习笔记2--对镜像/容器的命令操作

    Docker启动一个Centos镜像 我们下载完成一个Centos镜像之后,开始启动 docker run -d -i -t <imageID> /bin/bash 这样就能启动一个一直停 ...

  6. docker学习笔记-常用镜像相关命令

    docker images # 1.使用 [root@iZbp13qr3mm4ucsjumrlgqZ ~]# docker images REPOSITORY TAG IMAGE ID CREATED ...

  7. docker学习笔记一:基本安装和设置容器静态ip

    docker是一个lxc升级版的容器类虚拟环境,具有快速部署,灵活,易迁移的虚拟机模式,现在各大公司已经开始广泛使用为了自己方便学习linux,需要多台虚拟机环境,但是vmware开启多台虚拟机时需要 ...

  8. Docker学习笔记--2 镜像的创建

    如果我们需要在Docker环境下部署tomcat.redis.mysql.nginx.php等应用服务环境,有下面三种方法: 1,根据系统镜像创建Docker容器,这时容器就相当于是一个虚拟机,进入容 ...

  9. Docker学习笔记-CentOS7镜像

    前言: 环境:centos7.5 64 位 正文: 第一步:下载centos7镜像 docker pull centos 第二步:建立centos7的容器 sudo docker run --priv ...

随机推荐

  1. 远程触发Jenkins的Pipeline任务的并发问题处理

    前文概述 本文是<远程触发Jenkins的pipeline任务>的续篇,上一篇文章实战了如何通过Http请求远程触发指定的Jenkins任务,并且将参数传递给Jenkins任务去使用,文末 ...

  2. C#实例 武汉肺炎全国疫情实时信息图

    如果需要查看更多文章,请微信搜索公众号 csharp编程大全,需要进C#交流群群请加微信z438679770,备注进群, 我邀请你进群! ! ! --------------------------- ...

  3. JS常见加密混淆方式

    目录 前端js常见混淆加密保护方式 eval方法等字符串参数 emscripten WebAssembly js混淆实现 JSFuck AAEncode JJEncode 代码压缩 变量名混淆 字符串 ...

  4. Tomcat配置Gizp 客户端使用okHttp3

    找到tomcat 在 server.xml 新增如下配置 <Connector connectionTimeout="20000" port="8088" ...

  5. 华为方舟编译器正式支持C语言:完全开源

    投递人 itwriter 发布于 2020-10-14 19:08 评论(15) 有1938人阅读 原文链接 2019 年 8 月底,华为方舟编译器(OpenArkCompiler)正式开源,迈出了跨 ...

  6. Mybatis老手复习文档

    Mybatis学习笔记 再次学习Mybatis,日后,有时间会把这个文档更新,改的越来越好,然后,改成新手老手通用的文档 1.我的认识 Mybatis 是一个持久层框架,(之前 我虽然学了这个myba ...

  7. 微信小程序 audio组件 默认控件 无法隐藏/一直显示/改了controls=‘false’也没用2019/5/28

    <audio>默认控件,如果需要隐藏,不需要特意设置controls = 'false',直接把这个属性删除即可,不然无论如何都会存在 之前,设置了controls = 'false' & ...

  8. Helium文档13-WebUI自动化-helium快速切换到selenium状态并调用其方法

    前言 前面说过helium是对Selenium 进行了封装,那么我们如何使用selenium的方法呢,通过下面的介绍,我们能够清楚在helium中能够使用selenium的任何方法 入参介绍 def ...

  9. C++20 多线程 std::jthread

    在C++20中新加了jthread类,jthread是对thread的一种封装 std::jthread 构造函数 (1)jthread() noexcept; (2)jthread( jthread ...

  10. RateLimiter的 SmoothBursty(非warmup预热)及SmoothWarmingUp(预热,冷启动)

    SmoothBursty 主要思想 记录 1秒内的微秒数/permitsPerSencond = 时间间隔interval,每一个interval可获得一个令牌 根据允许使用多少秒内的令牌参数,计算出 ...