1、Dockerfile
FROM python:3.5
COPY . /var/
WORKDIR /var/
RUN pip install -r requirements.txt
CMD ["python", "./test.py"]
FROM python:3.5 镜像源
COPY . /var/ 拷贝当前目录到镜像系统/var 注意点代表当前目录
WORKDIR /var/ 切换镜像目录相当于cd /var/
RUN pip install -r requirements.txt 运行pip安装包
CMD ["python", "./test.py"] 相当于 python ./test.py
2、requirements.txt
requests
3、test.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/6/20 10:04
# @Author : Py.qi
# @File : req_reqst.py
# @Software: PyCharm
from requests import request
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36'
}
response = request('GET', 'https://api.github.com/events',
headers=header) # 定义头信息发送请求返回response对象
print(response.url) # 返回请求的URL
print(response.status_code) # 返回状态码200
print(response.encoding) # 返回编码
print(response.text) # 返回响应的内容以unicode表示
print(response.headers) # 返回头信息
print(response.cookies) # 返回cookies CookieJar
print(response.json()) # 返回json数据