Correct deploy using Docker

a month ago

I have a project that requires [tesseract]() to be installed in the environment. I haven't found any other way to do this except using Dockerfile, but I have a lot of specific dependencies and I want to make sure everything is set up correctly. By specific, I mean:

  • tesseract

  • uv

I rarely use Docker in my projects, so I can't guarantee that this is correct

currently Dockerfile:

# Use official lightweight Python image
FROM python:3.12-slim

# Install system dependencies
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        tesseract-ocr \
        tesseract-ocr-eng \
        libtesseract-dev && \
    rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Install uv for dependency management
RUN pip install --no-cache-dir --upgrade pip uv

# Copy dependency files first
COPY pyproject.toml uv.lock ./

# Install Python dependencies using uv lock file
RUN uv sync --locked --no-dev --no-install-project
# Install project dependencies
RUN uv sync --locked --no-dev --no-editable

# Copy the rest of the application
COPY . .

# Entrypoint
CMD ["uv", "run", "main.py"]

pyproject.toml

[project]
name = "sniper"
version = "0.1.0"
description = "your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "aiohttp>=3.12.13",
    "base58>=2.1.1",
    "disnake>=2.10.1",
    "pillow>=11.3.0",
    "pydantic-settings>=2.10.1",
    "pytesseract>=0.3.13",
    "solana>=0.36.7",
]

[dependency-groups]
dev = [
    "ruff>=0.12.2",
]

[tool.ruff]
line-length = 80
target-version = "py312"

lint.select = [
    "F",
    "E",
    "W",
    "N",
    "B",
    "RUF"
]

lint.ignore = [
    "B904"
]

exclude = [
    ".git",
    ".idea",
    ".vscode",
    "venv/",
    ".venv",
    ".ruff_cache",
    "__pycache__"
]

[tool.ruff.format]
quote-style = "single"
Solved

0 Replies

AI generated Dockerfile…?


a month ago

yep))


No wonder it doesn't work…


a month ago

I don't understand anything about Docker at all.


Then learn…?


a month ago

To be honest, I didn't even try to start it up. I figured it would be better to ask for help


a month ago

I'm in the process


AI generating a Dockerfile and then asking for help without doing any research on your own is not learning


a month ago

be nice please


a month ago

Can you please close the ticket? I managed to install everything I needed and run the bot correctly with this Dockerfile:

# Use official lightweight Python 3.12 image
FROM python:3.12-slim

# Install Tesseract OCR and English language data (for pytesseract) 
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        tesseract-ocr \
        tesseract-ocr-eng \
        libtesseract-dev && \
    rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Install uv (Python dependency manager)
RUN pip install --no-cache-dir --upgrade pip uv

# Environment variables: avoid Python download, compile pyc files
ENV UV_PYTHON_DOWNLOADS=never \
    UV_COMPILE_BYTECODE=1 \
    UV_NO_SYNC=1

# Copy dependency definition and lock files
COPY pyproject.toml uv.lock ./

# Install only production dependencies (no dev deps, skip project itself)
RUN uv sync --locked --no-dev --no-install-project

# Copy application source code
COPY . . 

# Install the project into the environment (non-editable mode for prod)
RUN uv sync --locked --no-dev --no-editable

# Entrypoint: run the Discord bot with uv
CMD ["uv", "run", "main.py"]

a month ago

!s


Status changed to Solved brody 27 days ago