首页  

python http server docker 镜像制作     所属分类 docker 浏览量 761
Dockerfile	
hello.html	
hello.txt	
start.sh


Dockerfile FROM python:latest RUN mkdir /www WORKDIR /www ADD hello.txt . ADD hello.html . RUN pwd WORKDIR / ADD start.sh . # RUN chmod +x /start.sh WORKDIR /www # CMD ["/start.sh"] CMD ["python","-m","http.server","8030"]
基础镜像 python docker images REPOSITORY TAG IMAGE ID CREATED SIZE python latest 2e005b03234c 22 hours ago 867MB
docker build -t pythonhttpserver . docker run --name my_python_http_server -p 8030:8030 -it pythonhttpserver /bin/sh 删除容器 docker rm my_python_http_server 删除镜像 docker rmi pythonhttpserver docker images REPOSITORY TAG IMAGE ID CREATED SIZE pythonhttpserver latest ab1b2dca1d5e 4 minutes ago 867MB python latest 2e005b03234c 22 hours ago 867MB docker run --name my_python_http_server -p 8030:8030 -d pythonhttpserver 6c0090a3ac042cb0125dff9196644569fa81b42f28abbef126cf78c9772c858a docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/start.sh": permission denied: unknown.
RUN chmod +x /start.sh CMD ["/start.sh"] 启动报错 docker logs my_python_http_server standard_init_linux.go:228: exec user process caused: exec format error start.sh 增加 #!/bin/sh 使用 CMD ["python","-m","http.server","8030"] 启动成功 http://127.0.0.1:8030/ http://127.0.0.1:8030/hello.html
几种写法 CMD ["python","-m","http.server","8030"] # 不需要可执行权限 CMD ["sh","/start.sh"] # 需要可执行权限 且加上 #!/bin/sh RUN chmod +x /start.sh CMD ["/start.sh"]
https://gitee.com/dyyx/hellocode/tree/master/web/tech/docker/pythonhttpserver

上一篇     下一篇
机器学习一般流程

docker镜像导入导出

机器学习基础

Python pip 安装

python pip 配置国内镜像

Docker三剑客