Docker 打镜像,部署测试环境

部署运行你感兴趣的模型镜像

第一步:上传项目代码到服务器

●git clone 复制代码到本地

C:\Users\Administrator># git clone https:xxx
Cloning into 'ai-call'...
remote: Counting objects: 11024, done
remote: Finding sources: 100% (11024/11024)
remote: Total 11024 (delta 7516), reused 10977 (delta 7516)
Receiving objects: 100% (11024/11024), 56.45 MiB | 1.06 MiB/s, done.
Resolving deltas: 100% (7516/7516), done.
curl: option --git-dir`/hooks/commit-msg: is unknown
curl: try 'curl --help' for more information

●在C:\Users\Administrator 中找到下载的代码目录ai-call,打包成ai-call.zip

●上传本地代码ai-call.zip和依赖文件requirements.txt 到服务器中

C:\Users\Administrator># scp ./ai-call.zip root@xx.xx.xx.xx:/tmp/
root@xx.xx.xx.xx's password:
ai-call.zip                                                                           100%   57MB   1.1MB/s   00:54
C:\Users\Administrator># scp ./requirements.txt root@xx.xx.xx.xx:/tmp/
root@xx.xx.xx.xx's password:
requirements.txt

●远程连接vm

C:\Users\Administrator># ssh xx.xx.xx.xx
The authenticity of host 'xx.xx.xx.xx (xx.xx.xx.xx)' can't be established.
ECDSA key fingerprint is SHA256://hW1Lx/RnHw2+ScKqSCuZC6ioECAQX6QMva/5josFE.
Are you sure you want to continue connecting (yes/no/[fingerprint])? ### yes
Warning: Permanently added 'xx.xx.xx.xx' (ECDSA) to the list of known hosts.
root@xx.xx.xx.xx's password:# 
Last failed login: Mon May  6 17:49:24 CST 2024 from 77.232.142.150 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Mon May  6 17:47:14 2024 from 113.140.93.162

第二步:拉取docker镜像

[root@VM-24-7-centos ~]# docker search python
NAME                              DESCRIPTION                                     STARS     OFFICIAL
python                            Python is an interpreted, interactive, objec…   9600      [OK]
pypy                              PyPy is a fast, compliant alternative implem…   389       [OK]
hylang                            Hy is a Lisp dialect that translates express…   60        [OK]
circleci/python                   Python is an interpreted, interactive, objec…   88
cimg/python                                                                       15
bitnami/python                    Bitnami container image for Python              27
okteto/python                                                                     0
appdynamics/python-agent-init     AppDynamics Repository for Python agent inst…   0
rapidfort/python-chromedriver                                                     12
pachyderm/python-sdk-ci-testing                                                   0
airbyte/python-connector-base                                                     0
chainguard/python                 Minimal Python image based on Wolfi.            1
intel/python                                                                      0
pachyderm/python-build                                                            0
ubuntu/python                     A chiselled Ubuntu rock with the Python runt…   1
clearlinux/python                 Python programming interpreted language with…   10
faucet/python3                     Python3 docker image for amd64                 7
openwhisk/python3action           Apache OpenWhisk runtime for Python 3 Actions   6
openwhisk/python2action           Apache OpenWhisk runtime for Python v2 Actio…   2
paketobuildpacks/python                                                           0
mirantis/python-operations-api    https://mirantis.jira.com/browse/IT-40189       0
okteto/python-fastapi                                                             0
submitty/python                   Official Repository for Submitty Python Imag…   0
opensuse/python                   openSUSE base image with python                 0
paketobuildpacks/python-start                                                     0

[root@VM-24-7-centos ~]# docker pull python
Using default tag: latest
latest: Pulling from library/python
1468e7ff95fc: Pull complete
2cf9c2b42f41: Pull complete
c4c40c3e3cdf: Pull complete
c05cc1123d7e: Pull complete
b6f29ccdcc55: Pull complete
e92dd62b776a: Pull complete
672dd3aca43e: Pull complete
f1a702319ca9: Pull complete
Digest: sha256:f78ea8a345769eb3aa1c86cf147dfd68f1a4508ed56f9d7574e4687b02f44dd1
Status: Downloaded newer image for python:latest
docker.io/library/python:latest

[root@VM-24-7-centos ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
python       latest    6825e5e3d255   4 weeks ago   1.02GB

第三步:跑容器

[root@VM-24-7-centos ~]# docker run -itd --name test python bash
898b3020e699530f1c5d09c6daa80a34b41b63db23cbdad3fad42207e8d8801f

[root@VM-24-7-centos ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND     CREATED          STATUS          PORTS     NAMES
898b3020e699   python    "python3"   16 seconds ago   Up 15 seconds             test

第四步:复制项目代码ai-call.zip 和依赖文件requirements.txt到容器内

root@898b3020e699:/tmp# exit    #退出容器
[root@VM-24-7-centos ~]# cd ../   #切换到tmp目录下
[root@VM-24-7-centos /]# cd tmp
[root@VM-24-7-centos tmp]# docker cp ai-call.zip test:/tmp/
Successfully copied 59.5MB to test:/tmp/
[root@VM-24-7-centos tmp]# docker cp requirements.txt test:/tmp/
Successfully copied 3.07kB to test:/tmp/

第五步:进入容器,安装相关依赖

root@898b3020e699:/tmp# exit
exit
[root@VM-24-7-centos ~]# cd ../
[root@VM-24-7-centos /]# cd tmp
[root@VM-24-7-centos tmp]# ls
ai-call.zip                   gpudirect_rdma_setup.sh   nv_gpu_conf.log   systemd-private-59972f4035da4c8db147ef57abfd19ac-ntpd.service-T9C9GY
cpuidle_support.log           net_affinity.log          requirements.txt  tat_agent
cvm_init.log                  nv_driver_install.log     setRps.log        tlinux_xps.log
disable_rt_runtime_share.log  nvenc_ai_sdk_install.log  set_xps.log       virtio_blk_affinity.log
gpudirect_rdma_setup.log      nvenc_ai_sdk_install.sh   stargate.lock     ydeye_install.log
root@898b3020e699:/tmp# pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
Looking in indexes: https://mirrors.aliyun.com/pypi/simple
Collecting amqp==5.1.1 (from -r requirements.txt (line 1))
  Using cached https://mirrors.aliyun.com/pypi/packages/de/a3/e7b3b9d34239bae066df135060e225929d639731050c920fdc740d6b7897/amqp-5.1.1-py3-none-any.whl (50 kB)
root@898b3020e699:/tmp# exit
exit

第六步:将项目代码ai-call.zip拷贝至容器内,并进行解压

[root@VM-24-7-centos tmp]# docker cp ./ai-call.zip test:/tmp/
Successfully copied 59.5MB to test:/tmp/
[root@VM-24-7-centos tmp]# docker cp ./requirements.txt test:/tmp/
Successfully copied 3.07kB to test:/tmp/
[root@VM-24-7-centos tmp]# docker exec -it test bash
root@898b3020e699:/# cd tmp
root@898b3020e699:/tmp# ls
ai-call.zip  requirements.txt
root@898b3020e699:/tmp# unzip ai-call.zip
root@898b3020e699:/tmp# ls
ai-call  ai-call.zip  requirements.txt
root@898b3020e699:/# exit
exit

第七步:打包当前容器为新镜像

[root@VM-24-7-centos tmp]# docker commit -m miaoshu test
sha256:0140e41115e1d71f89948366004df418cf18d9d5b836227f2520b2b505675eca

第八步:给新镜像打上标签以及名称

[root@VM-24-7-centos tmp]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
<none>       <none>    0140e41115e1   53 seconds ago   1.37GB
python       latest    6825e5e3d255   4 weeks ago      1.02GB
[root@VM-24-7-centos tmp]# docker tag 0140e41115e1 test01:v1.0
[root@VM-24-7-centos tmp]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
test01       v1.0      0140e41115e1   2 minutes ago   1.37GB
python       latest    6825e5e3d255   4 weeks ago     1.02GB

第九步:启动新镜像

[root@VM-24-7-centos tmp]# docker run -itd --name test01 -p 8002:8002 0140e41115e1
e3ba75d2bc2c88c00c5e6c75731c146cbb67496426ff1a5d54ab1627b199a8e1
[root@VM-24-7-centos tmp]# docker ps -a
CONTAINER ID   IMAGE          COMMAND     CREATED          STATUS          PORTS                                       NAMES
e3ba75d2bc2c   0140e41115e1   "python3"   7 seconds ago    Up 6 seconds    0.0.0.0:8002->8002/tcp, :::8002->8002/tcp   test01
898b3020e699   python         "python3"   36 minutes ago   Up 36 minutes                                               test

第十步: 启动服务

[root@VM-24-7-centos tmp]# docker exec -it test01 bash
root@e3ba75d2bc2c:/# cd tmp/ai-call/ai_call/
root@e3ba75d2bc2c:/tmp/ai-call/ai_call# ls
__init__.py  ai_call  celery_tasks  manage.py  script  start_web.sh
root@e3ba75d2bc2c:/tmp/ai-call/ai_call# python3 manage.py runserver python3 manage.py 0.0.0.0:8002
2024-05-13 16:27:50 INFO autoreload 677 Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
May 13, 2024 - 16:27:51
Django version 4.1.5, using settings 'ai_call.settings.settings'
Starting development server at http://0.0.0.0:8002/
Quit the server with CONTROL-C.

第十一步:在服务器中查看ip,将eth0中的inet地址 + 设置的端口发给前端,例如xx.xx.xx.xx:8002

[root@VM-24-7-centos ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 52:54:00:2e:65:d0 brd ff:ff:ff:ff:ff:ff
    inet xx.xx.xx.xx/22 brd 10.0.27.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe2e:65d0/64 scope link
       valid_lft forever preferred_lft forever
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:17:59:c0:f7 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:17ff:fe59:c0f7/64 scope link
       valid_lft forever preferred_lft forever
13: veth45bf11f@if12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
    link/ether fe:6c:7b:89:6b:14 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::fc6c:7bff:fe89:6b14/64 scope link
       valid_lft forever preferred_lft forever
15: veth9ecb153@if14: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
    link/ether 3a:c2:b3:fe:36:35 brd ff:ff:ff:ff:ff:ff link-netnsid 1
    inet6 fe80::38c2:b3ff:fefe:3635/64 scope link
       valid_lft forever preferred_lft forever

附录:代码小结

#克隆代码到本地
git clone https:xxx
scp ./ai-call.zip root@xx.xx.xx.xx:/tmp/
scp ./requirements.txt root@xx.xx.xx.xx:/tmp/
#连接服务器
ssh root@xx.xx.xx.xx
#搜索远端镜像
docker search python
#拉镜像
docker pull python
#查看本地镜像,是否拉取镜像成功
docker images
# 如果有 删掉 docker rmi 镜像id
#跑容器
docker run -itd --name test python bash
#将代码 和 依赖 从服务器复制到容器内
docker cp 项目代码所在路径 容器名:容器内路径
docker cp requrements.txt 容器名:容器内路径
docker images
#进入容器
docker exec -it test bash
#在容器里安装依赖文件
pip3 install -r requirements.txt  -i https://mirrors.aliyun.com/pypi/simple
#提交容器
docker commit -m '描述信息' 容器名
#打新的镜像
docker tag 新镜像id 新镜像名:版本号
#跑容器
docker run -itd --name 新容器名 -p 宿主机端口:容器内服务端口  新镜像id  
#起服务
cd /tmp/ai-call/ai-call/
python3 manage.py runserver 0.0.0.0:8002

您可能感兴趣的与本文相关的镜像

Python3.9

Python3.9

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论 7
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值