1、fastapi的目录结构
2、DockerFile文件的编写
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
COPY ./app /app
RUN /usr/local/bin/python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple/
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
3、生成Docker镜像
docker build -t myimage ./
4、然后将镜像推送到服务器上的harbor中
4.1.配置docker-ce镜像加速和信任私有仓库xxx.xxx.xxx.xxx
# 这里的xxx.xxx.xxx.xxx是我们服务器的ip
cat > /etc/docker/daemon.conf
{
"registry-mirrors": ["https://ofjd111b.mirror.aliyuncs.com"],
"insecure-registries": ["xxx.xxx.xxx.xxx"]
}
4.2修改/usr/lib/systemd/system/docker.service文件将ExecStart=/usr/bin/dockerd -H fd:// -- containerd=/run/containerd/containerd.sock 修改为ExecStart=/usr/bin/dockerd -H fd:// -- containerd=/run/containerd/containerd.sock --insecure-registry=xxx.xxx.xxx.xxx】
4.3 重启Docker
systemctl daemon-reload
systemctl restart docker
4.4 这里还有一步就是往harbor上推送镜像
5、然后连接我们的服务器
ssh lbx@192.168.132.165
6、从服务器的harbor仓库进行拉取镜像,然后在run