欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > docker 创建Dockerfile

docker 创建Dockerfile

2025/7/4 5:20:35 来源:https://blog.csdn.net/weixin_40777649/article/details/144117390  浏览:    关键词:docker 创建Dockerfile

一、定义

1.用Dockerfile 创建镜像。
2.设置自启动方式二:
3.容器自启动
4.glm4 容器部署案例

二、实现

1.用Dockerfile 创建镜像。
创建空文件夹:

mkdir /myfile
cd /myfile
pwd

在这里插入图片描述
2.编写Dockerfile

FROM pytorch/pytorch:2.1.0-cuda12.1-cudnn8-devel
# 指定作者和邮箱
MAINTAINER cnki<cnki@123.com>
#设置环境
ENV MYPATH /usr/local
WORKDIR $MYPATH
#更新apt-get    
RUN apt-get update  
# 安装vim编辑器
#RUN apt-get install install vim#安装库 ADD是相对路径,把requirement.txt添加到容器中,安装包必须要和Dockerfile文件在同一位置
COPY requirement.txt /usr/local
RUN cd /usr/local
RUN pip install numpy
RUN pip install -r /usr/local/requirement.txt -i https://pypi.tuna.tsinghua.edu.cn/simple# ADD是相对路径,把包添加到容器中,安装包必须要和Dockerfile文件在同一位置
COPY hello.py /usr/local/#启动文件添加到容器
COPY start.sh /usr/local/
RUN chmod +x /usr/local/start.sh EXPOSE 80#############遇到的问题,docker 执行指令无法执行#############
# 容器启动执行的默认命令   
CMD echo $MYPATH
CMD echo "success--------------ok"
CMD /bin/bash
ENTRYPOINT ["/bin/sh", "-c", "/usr/local/start.sh"]     #执行失败
CMD ["ls", "/usr/local"]   #执行失败# docker run --entrypoint "sh /usr/local/start.sh" myenv:1.5   方式二: 找不到路径 

3.构建
在myfile目录下构建镜像

# 注意:定义的TAG后面有个空格,空格后面有个点
# docker build -t 新镜像名字:TAG .
docker build -t myenv:1.5 .

在这里插入图片描述
在这里插入图片描述
4.运行镜像
docker run -d myenv:1.5

2.设置自启动方式二 : 简单粗暴

vim /root/start.sh
######
chmod +x /root/start.sh
vim /root/.bashrc写入的内容
############################################
# start hello.py 
if [ -f /root/start.sh ]; then/root/start.sh
fi

在这里插入图片描述
在这里插入图片描述
3.容器自启动
docker exec -it --restart=always xxxx /bin/bash

4.glm4 容器部署案例

FROM pytorch/pytorch:2.1.0-cuda12.1-cudnn8-devel
# 指定作者和邮箱
MAINTAINER cnki<cnki@123.com>
#设置环境
ENV MYPATH /home
WORKDIR $MYPATH
#更新apt-get    
RUN apt-get update  #安装库 ADD是相对路径,把requirement.txt添加到容器中,安装包必须要和Dockerfile文件在同一位置
COPY requirement.txt /home
RUN cd /home
RUN pip install -r /home/requirement.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cu121
RUN pip install vllm==0.6.4COPY glm4-9b-chat /home/glm4-9b-chat
#启动文件添加到容器
COPY start.sh /root
RUN chmod +x /root/start.sh EXPOSE 80

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com