torch docker超简单制作

1、python 整理环境

# -*- encoding: utf-8 -*-
# !/usr/bin/env python
'''
@File    : test.py
@Time    : 2022/9/19 9:14
@Author  : Fan LR
@Version : 1.0
@Contact : 1243124253@qq.com
@License : (C)Copyright 2021-2022
@Desc    : 
'''
# here put the import lib


import os, sys

# 找到当前目录
project_root = os.path.dirname(os.path.realpath(__file__))
print(project_root)

# 找到解释器,虚拟环境目录
python_root = sys.exec_prefix
print(python_root)

# 拼接生成requirements命令
command = python_root + '\Scripts\pip freeze > ' + project_root + '\\requirements.txt'
print(command)

# 执行命令。
os.system(command)


ps:注意规范一下 requirements.txt看能不能用

2、构建环境

FROM pytorch/pytorch:1.8.0-cuda11.1-cudnn8-devel

#作者名
MAINTAINER Fan LR 1243124253@qq.com

# 设置 python 环境变量
ENV PYTHONUNBUFFERED 1
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV LANGUAGE C.UTF-8

# 创建 code 文件夹并将其设置为工作目录
RUN mkdir /code
WORKDIR /code

# 更新 pip
RUN pip install -i https://pypi.mirrors.ustc.edu.cn/simple pip -U
# 设置pip源
RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple

# 将 requirements.txt 复制到容器的 code 目录
ADD requirements.txt /code/

# 安装库
RUN pip install -r requirements.txt

# 运行服务
CMD nohup python src/api.py &> run.log & /bin/sh -c "tail -f 50 run.log"

3、开始build

docker build -t pytorch1.8:v1 -f ./Dockerfile .
  • -t 镜像名
  • -f dockerfile 路径
    – 最后面加个点

4、打包(另存为)新镜像

另存为:

docker commit id images_name

导出:

docker save -o 文件名 镜像名
docker save -o pytorch1.8.tar 1cf96f49742d

5、加载

docker load -i 文件名 镜像名

6、运行

docker run -it -p 端口映射 -v 数据挂载 --name 镜像名

docker run -it -p 7671:7671 -v  E:\code2022\court_ana:/code --name court_anav1.0 1cf96f49742d
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值