compose icon indicating copy to clipboard operation
compose copied to clipboard

Watch different command/entrypoint

Open zoriya opened this issue 7 months ago • 7 comments

Description

When running with docker compose watch, i want my service to start their dev servers (those that support hotreloading & watch files)

When running with docker compose up, i want services to use their prod server (that will not start a file watcher & so on)

I was hoping to find something like services.app.develop.entrypoint or services.app.develop.command

Potential example:

services:
  web:
    build: .
    command: npm start
    develop:
      command: npm dev
      watch:
        - action: sync
          path: ./web
          target: /src/web
          ignore:
            - node_modules/
        - action: rebuild
          path: package.json

zoriya avatar May 15 '25 09:05 zoriya

watch is integrated in docker compose up (by adding --watch flag) and can even be activated dynamically, which would prevent such feature to be supported. For your use-case, a common practice is to use a compose-dev.yaml override file to define development-focussed overrides, typically changing entrypoint/command to enable dynamic reloading, or additional port exposed to plug a debugger

ndeloof avatar May 16 '25 09:05 ndeloof

Activating dynamically the watch (when there's a service.app.develop.command) could just trigger a restart action, i don't see how it would prevent the feature from being supported.

I currently use a docker-compose.dev.yaml for this purpose (and learned about the --watch recently) & would love if docker compose could allow us to move to a single one (so allowing dev specific env/ports...) If this is not a goal, I could understand not wanting to support a dev specific entrypoint too. I just felt like a toggleable watch was a step in this direction & thought that the missing entrypoint override was an oversight.

zoriya avatar May 16 '25 10:05 zoriya

I had in mind we introduce development-only additional attributes in the develop section that would be independent from watch feature, i.e if you run docker compose up in development mode (TBD) this would merge the main service definition with some overrides set in develop, typically changing command, adding ports or volumes, etc.

ndeloof avatar May 16 '25 12:05 ndeloof

this would be awesome, is there a tracking issue somewhere or is this only an idea for now?

zoriya avatar May 16 '25 12:05 zoriya

nope, that's just an idea I have in mind for long time but didn't created an issue for it. Let's use this one :P

ndeloof avatar May 16 '25 16:05 ndeloof

I had in mind we introduce development-only additional attributes in the develop section that would be independent from watch feature, i.e if you run docker compose up in development mode (TBD) this would merge the main service definition with some overrides set in develop, typically changing command, adding ports or volumes, etc.

That sounds super interesting, how do you think development mode should be activated?

robinhickmann avatar May 25 '25 10:05 robinhickmann

@robinhickmann TBD. Could be a flag --develop and/or an environment variable COMPOSE_DEVELOP, or ... any suggestion is welcome

ndeloof avatar May 25 '25 14:05 ndeloof