赞
踩
#Windows 11#Dockerfile#Python
pip freeze > requirements.txt
改命令将已安装的所有依赖包及其版本号导出到一个名为requirements.txt的文本文件中。你可以打开该文件查看已安装的依赖包及其版本

- # 使用Python 3.9 作为基础镜像
- FROM python:3.9
-
- # 设置工作目录
- WORKDIR /app
-
- # 将当前目录下的所有文件复制到容器的工作目录中
- COPY . /app
-
- # 安装依赖包
- RUN pip install --no-cache-dir -r requirements.txt
-
- # 设置环境变量
- ENV PYTHONUNBUFFERED=1
-
- # 定义容器启动时执行的命令
- CMD ["python", "/app/main.py"]

在根目录执行命令:
docker build -t 服务名字:版本 .
在构建镜像的时候报错
- error during connect: this error may indicate that the docker daemon is not running: Get "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/version": open //./pipe/docker_engine: The system cannot find the file specified.
- Client:
- Cloud integration: v1.0.35-desktop+001
- Version: 24.0.5
- API version: 1.43
- Go version: go1.20.6
- Git commit: ced0996
- Built: Fri Jul 21 20:36:24 2023
- OS/Arch: windows/amd64
- Context: default

解决方法:
网上众说纷纭,我是Windows的命令行cmd 中输入:bcdedit /set hypervisorlaunchtype auto 再重開機,再在Windows上登录Docker。再构建镜像就没有问题了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。