发布时间: 2023-6-15 文章作者: myluzh 分类名称: Docker 朗读文章
import http.server import socketserver import socket class MyHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() # 输出 "Hello, World!" self.wfile.write(b"Hello, World!<br>") # 输出本机hostname和ip地址 hostname = socket.gethostname() ip_address = socket.gethostbyname(hostname) self.wfile.write(f"Hostname: {hostname}<br>".encode()) self.wfile.write(f"IP Address: {ip_address}".encode()) PORT = 8080 # 启动服务器 with socketserver.TCPServer(("", PORT), MyHandler) as httpd: print(f"Serving at http://localhost:{PORT}") httpd.serve_forever()0x03 dockerfile文件 打包当前应用
FROM python:3.9-slim-buster RUN echo "deb http://mirrors.aliyun.com/debian/ buster main" > /etc/apt/sources.list RUN apt-get update && apt-get install -y lsof net-tools curl WORKDIR /app ADD . /app EXPOSE 8080 CMD ["python", "main.py"]
# 构建镜像 docker build -t hellok8s:latest .
标签: docker dockerfile
发表评论