Hello everybody. I’m still trying to figure out ho...
# general
b
Hello everybody. I’m still trying to figure out hot reload with docker-compose, does anyone have any examples of things working? Attached in the comments my compose, Dockerfile and BUILDs
Dockerfile
Copy code
FROM --platform="linux/amd64" python:3.11-slim

COPY src.python.backend/main.pex /bin/main
ENTRYPOINT ["/bin/main"]
Compose
Copy code
version: "3"
services:
  backend:
    container_name: xxxx-backend
    restart: unless-stopped
    image: xxxx-backend:latest
    ports:
      - "8000:8000"
    env_file:
      - .env.dev
    environment:
      - UVICORN_RELOAD=true
BUILDs
Copy code
docker_environment(
    name="python_base",
    image="python:3.11-slim",
    platform="linux_x86_64",
    python_bootstrap_search_path=[""],
)
docker_image(
    name="xxxx-backend",
    source="Dockerfile",
    restartable=True
)
python_sources(
    name="backend",
    restartable=True,
)

pex_binary(
    name="main",
    entry_point="main.py",
    dependencies=[":backend"],
    include_tools=True,
    environment="linux_docker", (references the env previously built)
    restartable=True,
)
With this setup I can run my image normally, but i’ve tried multiple different solutions I’ve seen here and can’t get hot reload working
( I’m running on a M1 macbook, when I tried building without the docker environment, my container would never run because of missing dependencies )
l
I was able to get hot reloading working with docker compose by setting the pex_binary layout to
'loose'
so that the PEX is an unpacked source folder then volume mapping the source code into the root of pex folder. So for your setup it might look like: BUILD
Copy code
pex_binary(
    name="main",
    entry_point="main.py",
    dependencies=[":backend"],
    include_tools=True,
    environment="linux_docker", (references the env previously built)
    restartable=True,
    layout='loose'
)
compose
Copy code
version: "3"
services:
  backend:
    container_name: xxxx-backend
    restart: unless-stopped
    image: xxxx-backend:latest
    ports:
      - "8000:8000"
    env_file:
      - .env.dev
    environment:
      - UVICORN_RELOAD=true
    volumes:
      - src/python/backend:/bin/main
b
I had seen a message you sent on another thread, but unfortunately that did not work for me 😕 Maybe because of the environment I’m using
l
How did it not work? What is the environment you're using?
b
It still would not reload when I saved code.
Copy code
docker_environment(
    name="python_base",
    image="python:3.11-slim",
    platform="linux_x86_64",
    python_bootstrap_search_path=[""],
)
this env
l
oh I see, the solution I found to work was to run the application code from the docker compose container rather than using
pants run
. I think in your case it'd be:
Copy code
docker compose run --rm --service-ports backend /bin/main