python项目Dockerfile

Dockerfile

# docker build --platform linux/amd64 -t ai-vanna:latest .
FROM python:3.12-slim
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Change the working directory to the `app` directory
WORKDIR /app

# Install dependencies
RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,source=uv.lock,target=uv.lock \
    --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
    uv sync --locked --no-install-project

# Copy the project into the image
ADD . /app
EXPOSE 6060
# Sync the project
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --locked

ENTRYPOINT ["sh", "-c", "uv run train.py && uv run server.py"]

docker-compose.yml

version: '3'
services:
  ai-vanna:
    image: ai-vanna:latest
    ports:
      - "6060:6060"
    volumes:
      - ./data:/app/data
      - ./train_data:/app/train_data
      - ./config.py:/app/config.py
    restart: always

脚本

# 生成镜像
docker build --platform linux/amd64 -t ai-vanna:latest .
# 导出镜像
docker save -o .tar ai-vanna:latest
# 加载镜像
docker load -i .tar
#重命名镜像
docker tag nginx:1.23 my_nginx:1.23
#打开镜像运行环境
 docker exec -it 6408cc170462  /bin/bash
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。