pythondockerdocker-composewatchearthly

Is it possible to use Docker Compose watch with an image created by Earthfile?


So I have this simple code to run.

import streamlit as st 

st.title("hellobored")

I created a docker image of this code with a simple earthfile with the command earthly +all

VERSION 0.8
streamlit: 
    FROM python:3.11-slim
    WORKDIR /src/app
    RUN apt-get update && apt-get install -y curl
    RUN python -m pip install --upgrade pip
    RUN pip install streamlit
    COPY ./hellobored.py /src/app/hellobored.py
    RUN ls
    EXPOSE 8501
    ENTRYPOINT ["streamlit", "run", "/src/app/hellobored.py", "--server.port=8501"]
    SAVE IMAGE hellobored

all: 
    BUILD +streamlit

I have a Docker Compose file that looks like this:

version: '3.8'
services:   
  streamlit:
    image: hellobored
    ports:
      - "8501:8501"
    develop: 
      watch:
      - path: ./
        action: rebuild
      - path: ./
        target: /src/app/
        action: sync 

I already tried using rebuild or sync separately, but both don't seem to work. I used docker compose up -d and docker compose watch to see the watch-related problem and received this error for the rebuild:

[+] Running 1/0manualy āœ” Container hellobored-streamlit-1 Running 0.0s can't watch service "streamlit" with action rebuild without a build context

And this error for the sync:

[+] Running 1/0 āœ” Container hellobored-streamlit-1 Running 0.0s none of the selected services is configured for watch, consider setting an 'develop' section

I can't find a way to give Docker Compose a build context for Earthly on the net, so I'm asking here. For note, I need the build to be done by Earthly because the images I create are 10GB, and Earthly can compile them in seconds. I need to watch because it would be really long to rebuild and reload manually after every change.


Solution

  • In your initial setup, the docker-compose-watch command failed because there was no build context specified. Docker Compose requires a build context to track changes and trigger rebuilds. Without a build context, the watch command cannot determine which files to monitor for changes.

    build:
      context: .