docker从镜像启动容器, 从容器制作镜像

docker从镜像启动容器:

docker run -d --name=entity -m 32G -p $port:$port -v $dirpath:/workdir $img_name:$tag python /workdir/run_server.py

docker run -it  --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=1 需要启动的docker名称 bash

docker run -it --name=entity --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=1 -m 32G -p 6688:6688 -v /opt/wwwroot/atom_guoyanan/deploy/project_recognize:/workdir hub.ifchange.com/nlp/gpu4:20190917 python /workdir/run_server.py

从容器制作镜像:

# 根据已经存在的容器guoyanan_entity来产生新的镜像project_entity:tf-1.12.0-gpu,
# 这样guoyanan_entity中手动安装的包就保存在了新的镜像中,以后无需再手动安装
docker commit guoyanan_entity hub.ifchange.com/nlp/project_entity:tf-1.12.0-gpu
制作镜像, 启动容器
制作镜像

根据 Dockerfile 制作镜像:
Dockerfile:

FROM tensorflow/tensorflow:1.12.0-gpu-py3

#创建workdir文件夹
RUN mkdir /workdir

# 代码添加到workdir文件夹
# ADD requirements.txt /workdir/

#设置workdir文件夹是工作目录
WORKDIR /workdir

# 安装包
# RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt

# CMD ["python", "/workdir/run_server.py"]
CMD ["/bin/bash"]

执行命令:

docker build -t hub.ifchange.com/nlp/tensorflow:1.12.0-gpu-py35 .

完成镜像制作。

启动容器

因为制作镜像时已经建立的工作目录,所以启动容器时将代码挂载到 镜像中的工作目录,进入容器之后,工作目录中就有启动代码:

docker run -it --name=guoyanan_entity --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=1 -m 32G -p 6688:6688 -v "$(pwd):/workdir" hub.ifchange.com/nlp/tensorflow:1.12.0-gpu-py35
/workdir# ls
README.md  data    init.sh  model             run_server.py       src       stop.sh
conf       docker  log      requirements.txt  run_server_copy.py  start.sh  test

安装一些包:

pip install etornado==0.1.7
pip install nlutools
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy==1.18.1
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple scipy==1.1.0
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple jieba==0.39
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple scikit_learn==0.22.1

退出容器,根据容器制作镜像:

docker commit guoyanan_entity hub.ifchange.com/nlp/project_entity:tf-1.12.0-gpu
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值